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

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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
Jos
Just now, Ambient said:

I'm just a little tired at this stage.

Just keep breathing, a step at a time and you'll be fine. ;) 

  • Like 2

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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

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

    • vin1
      By vin1
      i need a script that can replace words in text with other words from a words list
      it has to have 2 edit boxes input/output and a button "run"
      from word_list.txt it choses which word to replace with. words are separated with commas for multiple choice
       

       
       

       
       
      ; AutoIt GUI Example ; Created: 17/01/2005 - CyberSlug ; Modifed: 05/12/2011 - guinness ; Modifed: 09/06/2014 - mLipok #Region INCLUDE #include <AVIConstants.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #EndRegion INCLUDE #Region GUI GUICreate("Sample GUI", 400, 420) GUISetIcon(@SystemDir & "\mspaint.exe", 0) #EndRegion GUI #Region EDIT GUICtrlCreateEdit(@CRLF & " Sample Edit Control", 10, 10, 380, 175) GUICtrlSetTip(-1, '#Region EDIT') #EndRegion EDIT #Region EDIT2 GUICtrlCreateEdit(@CRLF & " Sample Edit Control", 10, 185, 380, 175) GUICtrlSetTip(-1, '#Region EDIT') #EndRegion EDIT2 #Region BUTTON GUICtrlCreateButton("Sample Button", 10, 360, 100, 30) GUICtrlSetTip(-1, '#Region BUTTON') #EndRegion BUTTON #Region GUI MESSAGE LOOP GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() #EndRegion GUI MESSAGE LOOP  
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question please
      Can we customize error messages in autoit script?
      I mean internal error messages
      for example
      AutoIt Error
      Line 4  (File "D:\my projects\NVDA Manager\New AutoIt v3
      Script.au3"):
      $script[1] = 1
      $script^ ERROR
      Error: Subscript used on non-accessible variable.
      For example, I want to customize this message
      Is this possible?
      am waiting for your answers
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to make a program that can look at a folder directory, find all the CSV files, and then add the data from CSV's to an array. 
      The problem I seem to be running into is on the 2nd iteration (2nd file) when the script will not create an array. Could someone please help? Thanks in advance
       
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> Global $MasterArray RefineData() Func RefineData() Local $i, $filenum, $file, $csvArray, $sFilePath = @ScriptDir $fileList = _FileListToArrayRec($sFilePath, "*.csv", 1) ;Create and array of all .csv files within folder ;=====Loop through the .csv files within the folder====== For $filenum = 1 To UBound($fileList) - 1 Step 1 $file = $fileList[$filenum] $sFilePath = $sFilePath & "\" & $file ;=====Create array based on csv file===== _FileReadToArray($sFilePath, $csvArray, $FRTA_NOCOUNT, ",") _ArrayDisplay($csvArray,"File: " & $filenum) If $filenum = 1 Then $MasterArray = $csvArray _ArrayDisplay($MasterArray, "Master") Else $MasterArray = _ArrayColInsert($MasterArray, UBound($MasterArray)) ;want column added at end For $i = 0 To UBound($MasterArray)-1 Step 1 $MasterArray[$i][UBound($MasterArray) - 1] = $csvArray[$i][4] Next _ArrayDisplay($MasterArray, "Master") EndIf Next EndFunc ;==>RefineData  
    • Ambient
      By Ambient
      I have tried several way sto get this to work to no avail. Any help would be appreciated. #include <ListViewConstants.au3> #include <GuiListView.au3> #include "GuiListViewEx.au3" $idItem = GUICtrlCreateListViewItem($r & " | " & $c & $adoRs.Fields("TransactionAmount").value & " | " & $Timestamp & " | " & _StringProper($adoRs.Fields("Tillid").value) & @CRLF & @CRLF & "Card Number : " & $cardnum & " " , $idListView) ConsoleWrite( "IDITEM" & $idItem) If STRINGLEFT($adoRs.Fields("TransactionAmount").value,1)= "-" Then Consolewrite(" String is Negative" & @CRLF) ;Drops in Here as expected ;GUICtrlSetColor(-1, $COLOR_RED) ; Colour line if item is negative this didn' work $TxC= _GUICtrlListView_SetTextColor($hListView, $CLR_RED) ; I also tried $TxC= _GUICtrlListView_SetTextColor(-1, 0xFF0000) CONSOLEWRITE("TEXTCOLOUR RETURNED " & $TxC & @crlf) ; This is returning True ELSE Consolewrite(" String is NOT Negative" & @CRLF) EndIf  
    • ur
      By ur
      In the autoit file, if we add multiple libraries (both internal and custom created one)
       
      When we compile the code and run the exe, some time we are getting runtime errors.
      But the line number of error is not showing the exact line number, might be it is including the line number count of libraries also.
      Can you please suggest how to get the exact error line number.
      So, it will be useful for debugging.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.