Ambient

Error When running complied Script

18 posts in this topic

#1 ·  Posted (edited)

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



@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

Nice one!

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

b

Edited by Ambient

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#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

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

#7 ·  Posted (edited)

Running full

SciTE
Version 3.6.6 

 

Edited by Ambient

Share this post


Link to post
Share on other sites

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
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

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

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

#12 ·  Posted (edited)

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                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Yes! I want to Exit if none of the

three file masks exists!

Share this post


Link to post
Share on other sites

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                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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
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. ;) 

2 people like this

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

    • houser747
      By houser747
      I have previously used _IEFormElementGetObjByName and _IEFormElementSetValue to enter text into a search box on a form and then submit the form.
      I am now trying to enter text into a search box which is not part of a form. 
      Here is the HTML from the website that i'm trying to enter the data on and then submit the search.
      <div class="row">
          <div class="form-group col-xs-12">
              <span id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_lblSearchText" for="input-search">Registreringsbeteckning</span>
              <div class="input-group col-xs-12">
                  <span id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_preSearchText" class="input-group-addon">SE -</span>
                  <input name="ctl00$FullWidthWithSubmenuContent$FullWidthContent$MainContent$AircraftRegistry$txtSearchText" type="text" value="DTH" id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_txtSearchText" class="form-control" />
              </div>
          </div>
      </div>
      <div class="row">
          <div class="form-group col-xs-12">
              <label class="sr-only" for="">Sök</label>
              <input type="submit" name="ctl00$FullWidthWithSubmenuContent$FullWidthContent$MainContent$AircraftRegistry$btnSearch" value="Sök" id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_btnSearch" class="btn btn-primary ladda-button" data-style="expand-right" />
          </div>
      </div>
      Many thanks in advance
      cheers
      Roger
    • robcull
      By robcull
      Hello all! I have had some issues reading text from different types of windows, occasionally, specifically with controlgettext. 
      **Before I begin, I know there are better ways to do what I attempt in the example below. That's not the point of this post. The point is my issues with controlgettext. 
      I am about to cite an example with an application you may be familiar with called SpeedFan (v4.52). My problem is not specific to speedfan, it is simply the most recent and easily reproducible example I can think of. 
      So, the goal of the script below is to get a string of text containing the current fan RPMs from the highlighted control in the screenshot below (see "speedfan_control_details.png").

      Now, here's a simple script for grabbing the window handle and reading the text from that control: 
      $wintitle = "SpeedFan 4.52" $controlID = "197934" ;will be reformatted as "[ID:######]" $hwnd = wingethandle($wintitle) if @error<>0 then msgbox(0, "WinGetHandle", "FAILURE. @error="&@error) Exit EndIf $text = ControlGetText($hwnd, "", "[ID:"&$controlID&"]") if @error=1 then msgbox(0, "ControlGetText", "FAILURE. @error="&@error) ;failure returns "" and @error=1 Exit EndIf msgbox (0, "ControlGetText", "SUCCESS. @error="&@error &@CRLF& "$text="&$text) ;success returns string and @error=0 You'll see that the ControlGetText operation runs without error, however it does not capture any text from the control. If you explore the other controls in this one window, you'll find mixed results across the board. Neither the temps nor voltages can be read, while the log field and some other elements can be read. Even when you read the text from the whole window, those elements are not included in the visible nor hidden texts. 
       
      I have run into this issue many times in the past- inconsistencies in the ability of autoit to interact with certain controls. What is it which makes this text different than any other readable texts? Is there an alternate method of reading the text in the window/control which could work? Any and all info to help me solve this mystery and satisfy my curiosity would be greatly appreciated. 
      Thanks  -Rob C
      PS: Running Autoit v3.3.14.2 on Win7 Ultimate x64
    • thoms
      By thoms
      Hello Forum,
      I'm trying to vertically center text in label controls, but no way. The search on the forum returns no result, or I don't search the right way
      When I insert a button and a label of same size close to each other, the text is centered on the button, but top aligned on the label, or edit. Which doesn't look really aesthetic
      Any idea is welcome
      Thanks in advance,
      Thoms
    • argumentum
      By argumentum
      UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email!
    • SkysLastChance
      By SkysLastChance
      I get this error, Whenever I try to find a date. Does anyone have any idea why? I saw some post from 2015, However I would imagine this is fixed by now. @water
      >"J:\Temporary Files\XXXXXXXXX\AutoIt\AutoIt\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\XXXXXX\Desktop\Call Report Automation.au3"     "J:\Temporary Files\XXXXXXXX\AutoIt\AutoIt\AutoIt\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR >Exit code: 1    Time: 5.791 #include <Excel.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2",3) _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") Sleep (1000) _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92") MsgBox (0,"Test",$oRead) UPDATE:
      If I take out this line it works. By works I mean I don't get the error. :/  However, I need it. I am just confused.
      _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7")  
      UPDATE 2: I also get this error when trying to use the helpfile examples. I have version 3.3.14.2
      \AutoIt\AutoIt\AutoIt\Include\Excel.au3" (670) : ==> The requested action with this object has failed.: $oSheet = $oWorkbook.Sheets($iIndexSheets) $oSheet = $oWorkbook^ ERROR >Exit code: 1 Time: 0.8931