Jump to content
Ambient

Error When running complied Script

Recommended Posts

Ambient

Okay guys, I have written a script which essentially runs once a week to copy files to a server. It also copies the files to a local directory. When I run in Autoit it works perfectly. When I compile and run I get the attached error. Any help would be appreciated. How should I debug this? I am not a programmer by the way but  love Autoit as it has done so much for me.

ReportsCopyError.png

Edited by Ambient
Just added some more info

Share this post


Link to post
Share on other sites
JLogan3o13

@Ambient unfortunately all of our crystal balls are in the shop. How about actually including your script, so we're not guessing at what you're trying to do?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Ambient

Nice one!

 

Share this post


Link to post
Share on other sites
Ambient

b

Edited by Ambient

Share this post


Link to post
Share on other sites
Ambient
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\..\Users\Support6\Downloads\Hopstarter-Sleek-Xp-Basic-Document.ico
#AutoIt3Wrapper_outfile=ReportsCopy.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Misc.au3>
#include <date.au3>
#include <Constants.au3>



Global $logfilepath = IniRead(@ScriptDir & "\Reports.ini", "LOG", "logpath", @ScriptDir & "\Reportscopy.log") ;Path to the logfile default script directory
Global $FileCount, $fl
Dim $FileCount = 0
$Today = @MDAY & "_" & @MON & "_" & @YEAR
$datetime = @MDAY & "_" & @MON & "_" & @YEAR & "_" & "_" & @HOUR & @MIN & @SEC
$g_szVersion = "Reportscopier"
$ilogsize = IniRead(@ScriptDir & "\Reports.ini", "Log", "logsize", "10") ; Size to keep log in mmegabytes
$Serverip = IniRead(@ScriptDir & "\Reports.ini", "SERVER", "ip", "192.168.1.10") ;Path to the server ipaddress
$Drive = IniRead(@ScriptDir & "\Reports.ini", "SERVER", "Drive", "J") ; Drive letter to map
$servershare = IniRead(@ScriptDir & "\Reports.ini", "SERVER", "ServerShare", "Users") ; Sharename to map to i.e
$FromPath = IniRead(@ScriptDir & "\Reports.ini", "COPY", "From", "C:\temp\Reports")
$serveruser = IniRead(@ScriptDir & "\Reports.ini", "Server", "user", "*****")
$serverpassword = IniRead(@ScriptDir & "\Reports.ini", "Server", "password", "*****")
$loc = IniRead(@ScriptDir & "\Reports.ini", "Server", "location", "0001")
$sext = IniRead(@ScriptDir & "\Reports.ini", "Copy", "ext", ".xls")
$sext1 = IniRead(@ScriptDir & "\Reports.ini", "Copy", "ext1", ".pdf")
$sext2 = IniRead(@ScriptDir & "\Reports.ini", "Copy", "ext2", ".csv")
$zip = IniRead(@ScriptDir & "\Reports.ini", "TILL", "7zip", "0")
$rmlogbk = 0
$rmdbbk = 0
Dim $answer = "RM6000_DSN", $Round
Dim $tblname1 = "Client"
$day = _DateDayOfWeek(@WDAY)
$sPID = "RepProcess.exe"
Dim $Dbservice = ""
Dim $i
Opt("TrayMenuMode", 1) ; stops script from being paused

;################################################################
;
; CHECK FIRST TO SEE IF THERE ARE REPORT FILES TO COPY IF NOT EXIT
;
;###############################################################

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

If Not FileExists(@ScriptDir & "\*" & $sext) Or Not FileExists(@ScriptDir & "\*" & $sext1) Or Not FileExists(@ScriptDir & "\*" & $sext2) Then
    _FileWriteLog($logfilepath, @ScriptDir & "\*" & $sext) Or Not FileExists(@ScriptDir & "\*" & $sext1) Or Not FileExists(@ScriptDir & "\*" & $sext2)
    _FileWriteLog($logfilepath, "                          N.B.   NO  " & $sext & " OR" & $sext1 & " OR" & $sext & " FILES EXIST FOR COPYING AT THIS TIME!")
    _FileWriteLog($logfilepath, "#######################################################################################################")

    Exit

Else
    ; Lets check to see if any of the processes have hung then and write to the log.
    If ProcessExists("reprocessor.exe") Then ; This shouldn't exist at the time we are running or copying reports

        $timer = TimerInit()
        While ProcessExists($sPID)
            Sleep(1000)
            If TimerDiff($timer) > 10 * 60 * 1000 Then ; still there after 5 mins close it.
                _ProcessCloseEx($sPID)
            EndIf
        WEnd
    EndIf

    ;Exit

EndIf


If _Singleton($g_szVersion, 1) = 0 Then
    ; We know the script is already running. Let the user know.
    ;_FileWriteLog($logfilepath, @UserName & " tried to run another instance of the software version " & $g_szVersion)
    MsgBox(0, $g_szVersion, $g_szVersion & "  is running. Using multiple copies of " & $g_szVersion & " at the same time breaks the [(Opus Solutions)] License!")
    Exit
EndIf


$MegaByte = ('1048576')
_FileSize_In_MegaBytes($logfilepath)
;$isize_bytes = FileGetSize($logfilepath)
;$isize_megas = $isize_bytes / 1048576
If $Round >= $ilogsize Then
    ;MsgBox(4096, "Result", $Round)
    If FileDelete($logfilepath) = 1 Then
        ;sleep(3000)
        ConsoleWrite("-> Deleted file: " & $logfilepath & @LF)
        _FileWriteLog($logfilepath, "Deleted old log as it was " & $Round & "Mb in size.")
    Else
        _FileWriteLog($logfilepath, "Failed to delete " & $logfilepath & "file may be current")
    EndIf
    _FileWriteLog($logfilepath, "File is now current so leaving until it is " & $ilogsize & "Mb in size.")
EndIf


$query1 = "SELECT clientname FROM " & $tblname1 & " where clientType='L' and clientnumber=" & $loc
;~  case  _GetIP()  = "93.107.102.59"
; RUN THE SELECT QUERY TO GET THE CLIENT NAME

$adoCon = ObjCreate("ADODB.Connection")
$val = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Sybase\SQL Anywhere\11.0", "LOCATION")

If FileExists($val & "\Bin32\dbeng11.exe") Then ;it's sybase 11
    $adoCon.Open("Driver={SYBASE SYSTEM 11};" & "Data source= " & $answer & " ;UID=dba;PWD=sql")
    ;$adoCon.Open ("Provider=ASAProv.11;" & "Data source= " & $ANSWER & " ;UID=dba;PWD=sql")
Else
    $adoCon.Open("Provider=ASAProv.90;" & "Data source= " & $answer & " ;UID=dba;PWD=sql")


EndIf

;Sybase 16     "Provider=SAOLEDB;DSN=SQL Anywhere 16 Demo"

$adoRs = ObjCreate("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.Open($query1, $adoCon)
If $adoRs.BOF And $adoRs.EOF Then ; Empty Record
    $Count = 0
Else
    Do
        $Storename = $adoRs.Fields("clientname" ).value
        $adoRs.MoveNext
    Until $adoRs.EOF
    $adoCon.Close
EndIf

;ConsoleWrite( _GetDOSOutput("ping 192.168.0.70") & @CRLF)



;$logfilepath = @scriptdir & "reports.log"
$Ip2ping = $Serverip ; ;Ping the server ip in here if the server is dead then Tooltip and run Posxpress3

For $n = 1 To 3
    $Rs = Ping($Ip2ping, 1000)
    If @error = 0 Then
        ;ToolTip("Ping " & $n & " of 5",10,10, "Response","Response from " & $ip2ping & " in "& $rs & " ms" ,1)
        ;ToolTip("Response from " & $ip2ping & " in "& $rs & " ms" ,10,10,"Ping " & $n & " of 3", "Response",1)
        ;_FileWriteLog($logfilepath, "Response from " & $ip2ping & " in "& $rs & " ms")
        ;Sleep(1000)
        ;ToolTip("")
    ElseIf @error = 1 Then
        ToolTip($Ip2ping & " is offline please check patch cable" & @CRLF & "Are you sure the server is switched on?", 10, 10, "Ping " & $n & " of 3", "Response", 1)
        _FileWriteLog($logfilepath, $Ip2ping & " is offline please check patch cable" & @CRLF & "Ensure the server is switched on?")
        ; Cannot Map Drive Run posxpress with the database thats there!
        Sleep(500)
        ToolTip("")

        If $n = 3 Then
            _FileWriteLog($logfilepath, $Ip2ping & " is offline please check patch cable")
            _FileWriteLog($logfilepath, "                          N.B.   NO COPY HAS TAKEN PLACE TODAY!                      ")
            ;_runposxpress(1)
        EndIf

        ;Msgbox(0,"Ping " & $n & " of 5", $ip2ping & " is offline please check cable",3)
    ElseIf @error = 2 Then
        ToolTip($Ip2ping & " is unreachable please check patch cable " & @CRLF & "Are you sure the server is switched on?", 10, 10, "Ping " & $n & " of 3", "Response", 1)
        _FileWriteLog($logfilepath, $Ip2ping & " is unreachable please check patch cable " & @CRLF & "Ensure sure the server is switched on?")
        Sleep(500)
        ToolTip("")
        If $n = 3 Then
            _FileWriteLog($logfilepath, $Ip2ping & " is unreachable please check patch cable ")
            _FileWriteLog($logfilepath, "                          N.B.   NO REPORTS COPIED TODAY!                      ")
            ;_runposxpress(1)
        EndIf
        ;Msgbox(0,"Ping " & $n & " of 5", $ip2ping & " is unreachable check cable",3)
    ElseIf @error = 3 Then
        ToolTip($Ip2ping & " is a bad destination " & @CRLF & "Are you sure the server is switched on?", 10, 10, "Ping " & $n & " of 3", "Response", 1)
        _FileWriteLog($logfilepath, $Ip2ping & " address is a bad destination " & @CRLF & "Are you sure the server is switched on?")
        Sleep(500)
        ToolTip("")
        If $n = 3 Then
            ; Cannot Map Drive Run posxpress with the database that there!
            _FileWriteLog($logfilepath, $Ip2ping & " is a bad destination cannot map drive, running Posxpress with Current data only")
            _FileWriteLog($logfilepath, "                          N.B.   NO TILL UPDATE HAS TAKEN PLACE TODAY!                      ")
            ;_runposxpress(1)
        EndIf
        ;Msgbox(0,"Ping " & $n & " of 5", $ip2ping & " is a bad destination",3)
    Else
        ToolTip($Ip2ping & "Unknown error encountered" & @CRLF & "Are you sure the server is switched on?", 10, 10, "Ping " & $n & " of 3", "Response", 1)
        _FileWriteLog($logfilepath, $Ip2ping & "An unknown error encountered" & @CRLF & "Are you sure the server is switched on?")
        Sleep(500)
        ToolTip("")

        If $n = 3 Then
            ; Cannot Map Drive Run posxpress with the database that there!
            _FileWriteLog($logfilepath, $Ip2ping & " an unknown error occurred running Posxpress with Current data only")
            _FileWriteLog($logfilepath, "                        N.B.   NO COPY HAS TAKEN PLACE TODAY!           ")
            ;_runposxpress(1)
        EndIf
        ;Msgbox(0,"Ping " & $n & " of 5", "Unknown error encountered",3)
    EndIf

    $i = $Rs + $i
Next

;ToolTip("Results",10,10,"Average roundtrip time: " & $i / 5 & " ms", "Response",1)

_FileWriteLog($logfilepath, _Iif($i / 5 > 0, " Server " & $Serverip & " is contactable Average roundtrip time from 3 pings :" & $i / 5 & " ms", " Server " & $Serverip & " UNREACHABLE Average roundtrip time from 3 pings:" & $i / 5 & " ms"))

; Lets make a folder locally first.

; If it does exist create it we'll call it Storename_reports and crate in root of C:
$local = "C:\" & $Storename & "_Reports"


If DirGetSize($local) = -1 Then
    _FileWriteLog($logfilepath, " Creating Folder C:\" & $Storename & "_Reports As None Exists")
    ;MsgBox(48, "My Message", "Directory does not exists!")
Else
    DirCreate("C:\" & $Storename & "_Reports")
EndIf
; Now lets Copy the files from the From Directory into this directory
_FileWriteLog($logfilepath, "LOCAL COPY FROM : " & $FromPath)

If DirGetSize($local & "\" & _DateDayOfWeek(@WDAY) & $Today) = -1 Then

    $Cr = DirCreate($local & "\" & _DateDayOfWeek(@WDAY) & $Today) ; Create it

    If $Cr = 1 Then

        _FileWriteLog($logfilepath, "SUCCESS CREATING LOCAL FOLDER  " & $local & _DateDayOfWeek(@WDAY) & $Today)
    Else

        _FileWriteLog($logfilepath, "Could Not Create Local Folder " & @CRLF & $local & "\" & _DateDayOfWeek(@WDAY) & $Today)
    EndIf
Else

    If DirGetSize($local & "\" & _DateDayOfWeek(@WDAY) & $Today) <> -1 Then

        _FileWriteLog($logfilepath, "Directory:" & @CRLF & $local & "\" & _DateDayOfWeek(@WDAY) & $Today & " Already Exists")
    EndIf
;~                              EndIf
    ;_FileWriteLog($logfilepath, "Folder Scan Complete. There were " & $FileCount & " Files in Folder on this run." & @CRLF & "Next Run" )
    $fl = ScanFolder($FromPath, "Local") ; SCAN THE REPORTS FOLDER AT LOCAL STORE CHECK FOR FILES THAT ARE ELIGIBLE FOR COPYING
    _FileWriteLog($logfilepath, "Folder Scan Complete. There were " & _Iif($FileCount = 0, "There Were No files to copy today.", " There were " & $FileCount & " Files copied Locally on this run."))
EndIf

; This is used for mapping the drive

;Server Copy Stuff below here.

$cmd = "net use " & $Drive & " \\" & $Serverip & "\" & $servershare & " " & $serverpassword & " /user:" & $serveruser & " /PERSISTENT:NO"

;Check First to see if there is a drive Mapped, if so delete it

DriveMapDel($Drive)
$Dr = DriveMapGet($Drive)
If $Dr = "" Then
    $String = $Drive & "\\" & $Serverip & "\" & $servershare & " 0" & $serveruser & $serverpassword
    _FileWriteLog($logfilepath, " NO " & $Drive & " DRIVE EXISTS. START MAPPING DRIVE : " & $Drive & "\\" & $Serverip & "\" & $servershare)
    ;_FileWriteLog($logfilepath, "net use " & $Drive  & " \\" & $Serverip & "\" & $servershare & " " &  $serverpassword  & " /user:" & $serveruser & " /PERSISTENT:NO")
    ;ConsoleWrite("net use " & $Drive  & " \\" & $Serverip & "\" & $servershare & " " &  $serverpassword  & " /user:" & $serveruser & " /PERSISTENT:NO" & @CRLF)
    Do
        ;Local $iRc= _Rundos("net use " & $Drive  & " \\" & $Serverip & "\" & $servershare & " " &  $serverpassword  & " /user:" & $serveruser & " /PERSISTENT:NO")

        Local $iRc = _FileWriteLog($logfilepath, _GetDosoutput($cmd))
        ;_FileWriteLog($logfilepath, "$IRC = " & $iRc )
    Until $iRc > 0

    Sleep(500)
    ;Msgbox(0,"Ping " & $n & " of 5","Response from " &  "net use " & $Drive  & " \\" & $Serverip & "\" & $servershare & " " &  $serverpassword  & " /user:" & $serveruser & " /PERSISTENT:NO "  & " in "& $rs & " ms")
    ; $RT=DriveMapAdd($Drive, "\\" & $Serverip & "\"& $servershare, 0, $serveruser, $serverpassword)
    _FileWriteLog($logfilepath, "CHECKING DRIVE:  " & $Drive)
    If DriveStatus($Drive) = "READY" Then
        _FileWriteLog($logfilepath, ";-)" & "DRIVE MAPPED SUCCESSFULLY! " & $Drive & "\ DRIVE MAPPED OKAY.....")
        Sleep(1000)
        ;ToolTip("Drive Mapped Successful!",10,10, $Drive &"\ drive mapped....." ,"Drive Mapping",1)
        ToolTip("DRIVE MAPPED SUCCESSFULLY!", 10, 10, $Drive & "\ DRIVE MAPPED.....", "Drive Mapping", 1)
        _FileWriteLog($logfilepath, ";-) HAPPY DAYS DRIVE MAPPED OK...HUSTON GOOD TO GO")
        ; ConsoleWrite("Drive Mapped Whoop.")
        Sleep(1000)
        ToolTip("")
    Else

        ToolTip("DRIVE MAPPING FAILED.", 10, 10, $Drive & "WASN'T MAPPED MAPPED IT MAY ALREADY EXIST OR NO SHARE EXISTS.....", 1)
        Sleep(1000)
        ToolTip("")

    EndIf


    ;_FileWriteLog($logfilepath, ";-) HAPPY DAYS DRIVE MAPPED OK...HUSTON GOOD TO GO")
    ;ConsoleWrite("before from path   " & $FromPath)
    If DriveStatus($Drive) = "READY" Then
        _FileWriteLog($logfilepath, "DRIVE STILL EXISTS. " & $Drive)

    Else
        _FileWriteLog($logfilepath, "MAPPING APPEARS TO HAVE DROPPED TO : " & $Drive)
    EndIf


    If FileExists($FromPath) Then ;If there is a rpt Folder.
        _FileWriteLog($logfilepath, "COPYING FROM : " & $FromPath)

;~                          If Not FileExists($Drive & "\" &  $Storename & "\" & _DateDayOfWeek( @WDAY ) & $today) Then   ; IF THERE IS NO REPORT FOLDER WITH DAY DATE NAME ON SERVER CREATE ONE
;~                                  _FileWriteLog($logfilepath, "NO FOLDER FOR TODAYS DATE " & $Storename & _DateDayOfWeek( @WDAY ) & $today & " SO CREATING ONE.")

        If DirGetSize($Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today) = -1 Then

            $Cr = DirCreate($Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today) ; Create it

            If $Cr = 1 Then

                _FileWriteLog($logfilepath, "SUCCESS CREATING FOLDER  " & _DateDayOfWeek(@WDAY) & $Today)
            Else

                _FileWriteLog($logfilepath, "Creating Server Folder failed. Could Not Create Folder 1:" & @CRLF & $Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today)
            EndIf
        Else

            If DirGetSize($Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today) <> -1 Then

                _FileWriteLog($logfilepath, "Directory:" & @CRLF & $Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today & " Already Exists")

            EndIf

;~                              EndIf
            ;_FileWriteLog($logfilepath, "Folder Scan Complete. There were " & $FileCount & " Files in Folder on this run." & @CRLF & "Next Run" )
            $fl = ScanFolder($FromPath, "Server") ; SCAN THE REPORTS FOLDER AT LOCAL CHECK FOR FILES THAT ARE ELIGIBLE FOR COPYING LOCALLY
            _FileWriteLog($logfilepath, "Folder Scan Complete. There were " & _Iif($FileCount = 0, "There Were No files to copy today.", " There were " & $FileCount & " Files copied from Folder on this run." & @CRLF & "NEXT COPY RUN BELOW."))
            _FileWriteLog($logfilepath, "#######################################################################################################")
            ;DriveMapDel($Drive)
            ; exit
        EndIf

    Else

        ;DriveMapDel($Drive) ;"Deleteing Mapped drive OK Already Exists "
        _FileWriteLog($logfilepath, "RE-MAPPING DRIVE : " & $Drive)

        ; MAY BE WORTH DOING A NETUSE HERE AS DRIVEMAPADD DOESN'T SEEM TO WORK IN WINDOWS 7
        Do
            Local $iRc = _FileWriteLog($logfilepath, _GetDosoutput($cmd))
            ;_FileWriteLog($logfilepath, "$IRC = " & $iRc )
        Until $iRc > 0

        Sleep(500)

;~      Local $iRc= _Rundos("net use " & $Drive  & " \\" & $Serverip & "\" & $servershare & " " &  $serverpassword  & " /user:" & $serveruser & " /PERSISTENT:NO")
;~        _FileWriteLog($logfilepath, "Second $IRC value = " & $iRc )
;~      Until $iRc > 0

        ;   ConsoleWrite($Drive & "\\" & $Serverip & "\" & $servershare & $serveruser & $serverpassword & @CRLF)
        If DriveStatus($Drive) = "READY" Then
            ;
            ToolTip("Drive Mapped Successful!", 10, 10, $Drive & "\ drive mapped.....", "Drive Mapping", 1)
            _FileWriteLog($logfilepath, ";-) HAPPY DAYS DRIVE MAPPED OK...HUSTON GOOD TO GO")
            Sleep(500)
            ToolTip("")
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;Drive mapped to share create a location folder for reports then copyin DAy numbers and delete temp files at store
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

            If Not FileExists($Drive & $Storename) Then
                If Not DirCreate($Drive & $Storename) Then
                    _FileWriteLog($logfilepath, ";-(" & "FAILED TO CREATE FOLDER " & $Drive & "\ " & $Storename & "On Server.")
                    ;MsgBox(8240, 'Directory Creation Failed', 'Could Not Create Folder:' & @CRLF & $Drive & $Storename)

                EndIf
                Sleep(500)
            Else
                _FileWriteLog($logfilepath, "Directory " & $Storename & " created.")
                ;ConsoleWrite("Directory " & $Storename & " created  or exists." & @CRLF & @CRLF)
            EndIf

            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

            ; Copy Reports to the appropriate folder then delete from local drive

            ;msgbox(0,"Mapped drive","Huston we don't have a problem")

            ;ConsoleWrite("before from path   " & $FromPath)


            If FileExists($FromPath) Then ;If there is a rpt Folder.
                _FileWriteLog($logfilepath, "Copying from path " & $FromPath)
                If Not FileExists($Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today) Then ; IF THERE IS NO REPORT FOLDER CREATE ONE ON SERVER
                    _FileWriteLog($logfilepath, "NO FOLDER ON SERVER: " & $Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today)
                    If Not DirCreate($Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today) Then
                        _FileWriteLog($logfilepath, "DIRECTORY CREATION FAILED ON SERVER 2. COULD NOT CREATE FOLDER :" & @CRLF & $Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today)
                    EndIf
                    Sleep(500)
                Else
                EndIf
                $fl = ScanFolder($FromPath, "Server") ; SCAN THE REPORTS FOLDER AT STORE CHECK FOR FILES THAT ARE ELIGIBLE FOR COPYING

                _FileWriteLog($logfilepath, "Folder Scan Complete. There were " & _Iif($FileCount = 0, "There Were No files to copy today.", $fl & " Files copied from Folder on this run." & @CRLF & "NEXT COPY RUN BELOW."))
                _FileWriteLog($logfilepath, "#######################################################################################################")

                ; exit
            EndIf
        EndIf
    EndIf
EndIf

;DriveMapDel($Drive)
Exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;FUNCTIONS BELOW HERE FUNCTIONS BELOW HERE FUNCTIONS BELOW HERE FUNCTIONS BELOW HERE ;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Func LogFile($FileName, $LocalORServer)
    ;Msgbox(0,"Logfile", $LocalORServer)
    _FileWriteLog($logfilepath, "Copying to " & $LocalORServer)
    Local $m
    Local $n = 0
    If $LocalORServer = "Server" Then
        If StringRight($FileName, 4) = ".pdf" Or StringRight($FileName, 4) = ".xls" Or StringRight($FileName, 4) = ".csv" Then
            Do
                $n = FileCopy($FileName, $Drive & "\" & $Storename & "\" & _DateDayOfWeek(@WDAY) & $Today & "\" & $datetime & "_" & GetFileName($FileName), 1)
                _FileWriteLog($logfilepath, _Iif($n = 1, ";-)" & " Success copying " & $FileName, ";-(" & " Failure copying " & $FileName))
            Until $n = 1
            If $n = 1 Then
                If $FileName <> "reportscopy.log" Or $FileName <> "reports.ini" Then
                    FileRecycle($FileName)
                EndIf
            Else
                _FileWriteLog($logfilepath, "Failed to Copy " & @CRLF & $FromPath & $FileName)
            EndIf

            ;ToolTip($FileName,0,0)

            $FileCount += 1
            ToolTip($FileName & " " & $FileCount, 0, 0)
        EndIf
    Else ;It's local so copy to local C:\ Storename drive
        If StringRight($FileName, 4) = ".pdf" Or StringRight($FileName, 4) = ".xls" Or StringRight($FileName, 4) = ".csv" Then
            Do
                $n = FileCopy($FileName, "C:\" & $Storename & "_Reports" & "\" & _DateDayOfWeek(@WDAY) & $Today & "\" & $datetime & "_" & GetFileName($FileName), 1)
                _FileWriteLog($logfilepath, _Iif($n = 1, ";-)" & " Success copying " & $FileName, ";-(" & " Failure copying " & $FileName))
            Until $n = 1
        EndIf

    EndIf

EndFunc   ;==>LogFile



Func ScanFolder($SourceFolder, $LocalORServer)
    _FileWriteLog($logfilepath, "Scanning Folder  " & $SourceFolder & " With " & $LocalORServer)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    ;MsgBox(0, "Scanfolder func", $LocalORServer)

    For $i = 1 To 3
        If $i = 1 Then
            _FileWriteLog($logfilepath, "Searching  Folder  for: " & $SourceFolder & "\*" & $sext)
            $Search = FileFindFirstFile($SourceFolder & "\*" & $sext)
        ElseIf $i = 2 Then
            _FileWriteLog($logfilepath, "Searching  Folder  for: " & $SourceFolder & "\*" & $sext1)
            $Search = FileFindFirstFile($SourceFolder & "\*" & $sext1)
        Else
            $i = 3
            _FileWriteLog($logfilepath, "Searching  Folder  for: " & $SourceFolder & "\*" & $sext2)
            $Search = FileFindFirstFile($SourceFolder & "\*" & $sext2)
        EndIf
        While 1
            If $Search = -1 Then
                ExitLoop
            EndIf

            $File = FileFindNextFile($Search)
            If @error Then ExitLoop

            $FullFilePath = $SourceFolder & "\" & $File
;~      "R" = READONLY
;~      "A" = ARCHIVE
;~      "S" = SYSTEM
;~      "H" = HIDDEN
;~      "N" = NORMAL
;~      "D" = DIRECTORY
;~      "O" = OFFLINE
;~      "C" = COMPRESSED (NTFS compression, not ZIP compression)
;~      "T" = TEMPORARY
;~      "X" = EFS ENCRYPTION
            $FileAttributes = FileGetAttrib($FullFilePath)

            If StringInStr($FileAttributes, "D") Then ; IF ITS A DIRECTORY RESCAN
                ScanFolder($FullFilePath, $LocalORServer)
            Else
                ;Msgbox(0, "Calling Logfile with",$LocalORServer)
                LogFile($FullFilePath, $LocalORServer)

            EndIf
            ;ConsoleWrite(" Fullpatf " & $FullFilePath & @crlf)
        WEnd
    Next
    FileClose($Search)
    Return $FileCount
EndFunc   ;==>ScanFolder

; #FUNCTION# ======================================================================================================
; Name...........: GetFileName
; Description ...: Returns the file name of the given file path
; Syntax.........: GetFileName($sFilePath)
; Parameters ....: $sFilePath - File path
; Return values .: Success - The file name
;                  Failure - -1, sets @error to:
;                  |1 - $sFilePath is not a string
; Author ........: Renan Maronni <renanmaronni@hotmail.com>
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===================================================================================================================

Func GetFileName($sFilePath)
    Local $aFolders = ""
    Local $FileName = ""
    Local $iArrayFoldersSize = 0

    If (Not IsString($sFilePath)) Then
        Return SetError(1, 0, -1)
    EndIf
    $aFolders = StringSplit($sFilePath, "\")
    $iArrayFoldersSize = UBound($aFolders)
    $FileName = $aFolders[($iArrayFoldersSize - 1)]
    Return $FileName

EndFunc   ;==>GetFileName


Func _FileSize_In_MegaBytes($File)
    $FileSizeInBytes = FileGetSize($File)
    $Equal = $FileSizeInBytes / $MegaByte
    $Round = Round($Equal, '2')
    Return $Round
EndFunc   ;==>_FileSize_In_MegaBytes

Func _File_GetDate($File)
    $File = FileGetShortName($File)
    $Ft = ""
    $fTime = FileGetTime($File, 1)
    For $i = 0 To 2
        $Ft &= $fTime[$i] & "/"
    Next
    Return StringTrimRight($Ft, 1)
EndFunc   ;==>_File_GetDate



;Kill Process's and Child Process's

Func _ProcessCloseEx($sPID)
    If IsString($sPID) Then $sPID = ProcessExists($sPID)
    If Not $sPID Then Return SetError(1, 0, 0)

    Return Run(@ComSpec & " /c taskkill /F /PID " & $sPID & " /T", @SystemDir, @SW_HIDE)
EndFunc   ;==>_ProcessCloseEx

;
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    ConsoleWrite("We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription)

    SetError(1); something to check for when this function returns
EndFunc  ;==>MyErrFunc


Func _GetDOSOutput($sCommand)
    Local $iPID, $sOutput = ""

    $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $sOutput &= StdoutRead($iPID, False, False)
        If @error Then
            ExitLoop
        EndIf
        Sleep(10)
    WEnd
    Return $sOutput
EndFunc   ;==>_GetDOSOutput

 

Edited by Ambient

Share this post


Link to post
Share on other sites
JLogan3o13

Are you using the full SciTE? Just running the SyntaxCheck (CTRL + F5) shows you the errors in that code.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Ambient

Running full

SciTE
Version 3.6.6 

 

Edited by Ambient

Share this post


Link to post
Share on other sites
JLogan3o13

Then if you hit CTRL+F5 you should see one glaring error on line 49


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Jos
39 minutes ago, JLogan3o13 said:

Then if you hit CTRL+F5 you should see one glaring error on line 49

This actually should work for both the included and Full SciTE versions. :) 
The main difference is that the Full version would run au3check by default unless a directive is used to not run it.

@Ambient, Show the full SciTE output pane info when running or compiling your script so we can tell what version you are running, in case you are interested.

Jos

  • Like 1

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Ambient

Thanks Guys how'd I miss that I will test and let you know. Thanks anway.

 

Share this post


Link to post
Share on other sites
Ambient

Okay! When I run this in my machine it works absolutely fine does all that I need it too. When I compile and run at remote machine it drops out at the below even though there are about 10 or 12 xls file in the script directory are there known issues with FileExists.  Thanks,  Jlogan3013 and Jos.


 

If Not FileExists(@ScriptDir & "\*" & $sext) Or Not FileExists(@ScriptDir & "\*" & $sext1) Or Not FileExists(@ScriptDir & "\*" & $sext2) Then
    ;_FileWriteLog($logfilepath, @ScriptDir & "\*" & $sext & "Or Not FileExists(@ScriptDir & "\*" & $sext1) Or Not FileExists(@ScriptDir & "\*" & $sext2)
    _FileWriteLog($logfilepath, "                          N.B.   NO  " & $sext & " OR" & $sext1 & " OR" & $sext & " FILES EXIST FOR COPYING AT THIS TIME!")
    _FileWriteLog($logfilepath, "#######################################################################################################")
    Exit

 

Share this post


Link to post
Share on other sites
Jos
44 minutes ago, Ambient said:

are there known issues with FileExists.  

There is a dot there but meant to be a question?

FileExits works fine, but maybe you need to give some more details on what you exactly want  to do and what fails as not all information is posted.
Do you want to exit when any of the 3 filemasks doesn't exists or should that be an AND relation?

Jos

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Ambient

Apologies! Yes, that is meant to be a question.  I want to copy files to a server and also locally. *.pdf,*.xls and *.csv from the scripts directory. When I Test this on my machine it works absolutely fine. When I test with the same exe on the machine I need it for it drops out even though the scripts directory has loads of .xls files.

Share this post


Link to post
Share on other sites
Ambient

Yes! I want to Exit if none of the

three file masks exists!

Share this post


Link to post
Share on other sites
Jos

Maybe  re-read the question i raised :  

26 minutes ago, Jos said:

Do you want to exit when any of the 3 filemasks doesn't exists or should that be an AND relation?

 because then the answer is No,  so the relation should be AND in stead of OR! ;)

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Ambient

Hi Jos . I will try what you have suggested .Thank's again for you help. I'm just a little tired at this stage.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • reida
      By reida
      Hello. On page there is mail address. How to keep in a text file this address? 
      It is page and email
      https://alpari.com/
      info@alpari.com
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • caramen
      By caramen
      Hey.  
       
      I requested help about how to get a value from a text in a variable. 
      Now i know how to do that. But i learned with the command FileRead. Now i whould like to know how to replace the command :
      FileRead('Dossier.txt') The purpose is to read a webpage text. To find some value inside. 
       
      Btw i tryed to play with WindowsInfo.au3 but i dont got much thing.  
    • Xandy
      By Xandy
      I'm listing the error message strings, and roughly matching the error code
      Is this how to do error reporting?  Is there a more simple way I don't know about?
      I realise I might not need to trap @error inside $error.  I like it this way b/c I have no fear of overwriting @error now; I don't even use it.
      Func Send_Connect($address, $port)     $socket = TCPConnect($address, $port)     $error = @error     If $error <> 0 Then         Local $aError[4] = ["-2 not connected.", _                             "1 IPAddr is incorrect.", _                             "2 port is incorrect."]         $aError[3] = "10060 Connection timed out."         If $error < 0 Then $error = 0         If $error > 2 Then $error = 3         MsgBox(0, "TCP Connect Error", $aError[$error], 0)         $socket = 0     EndIf     Return $socket EndFunc
    • therks
      By therks
      I'm trying to create a simple clock widget that automatically scales the text to the size of the window. I came up with the following method, but it doesn't work as well as I'd like. It especially has trouble scaling to the width of the window for some reason (in the example, try resizing the window to be narrow and tall).
      Does anyone have a better method?
      #include <Misc.au3> #include <WinAPIConv.au3> #include <GUIConstants.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) Global $_FONT_FAMILY = 'Arial', $_LB_TEXT Main() Func Main() _GDIPlus_Startup() Local $hGUI GUIRegisterMsg($WM_SIZE, WM_SIZE) $hGUI = GUICreate('', 300, 100, Default, Default, $WS_OVERLAPPEDWINDOW, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $_LB_TEXT = GUICtrlCreateLabel('This is a string', 0, 0, 300, 100, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($_LB_TEXT, _MeasureString($hGUI, GUICtrlRead($_LB_TEXT), $_FONT_FAMILY), 0, 0, $_FONT_FAMILY, 5) GUISetState() Local $iGM While 1 $iGM = GUIGetMsg() Switch $iGM Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GDIPlus_Shutdown() EndFunc Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) GUICtrlSetFont($_LB_TEXT, _MeasureString($hWnd, GUICtrlRead($_LB_TEXT), $_FONT_FAMILY), 0, 0, $_FONT_FAMILY, 5) EndFunc Func _MeasureString($hWnd, $sString, $sFont = 'Arial') Local $iError, $aSize, $hGraphic, $hFormat, $hFamily, $tLayout, $iFontSize, $hFont, $aInfo If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) EndIf $aSize = WinGetClientSize($hWnd) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($sFont) $tLayout = _GDIPlus_RectFCreate(0, 0, $aSize[0], $aSize[1]) $iFontSize = 0 Do If Not $hFamily Then $iError = 1 $iFontSize = 10 ExitLoop EndIf $iFontSize += 1 $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_FontDispose($hFont) If $aInfo[1] = 0 Then ExitLoop Until DllStructGetData($aInfo[0], 3) >= $aSize[0] Or DllStructGetData($aInfo[0], 4) >= $aSize[1] $iFontSize -= 1 _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return SetError($iError, 0, $iFontSize) EndFunc
×