rony2006 Posted July 23, 2015 Share Posted July 23, 2015 (edited) Hello,At work we have a computer that inspect every product for detecting bad mounting.I made made a script that back-up important files each day, on a USB stick because if the HDD fails, to have the important files on a external device.The code for back-up is this:#include <MsgBoxConstants.au3> backup() Func backup() FileDelete ("D:\SIRIUS\Applications\Coake\Images\Fehlerbilder\Kamera1\*.bmp") FileDelete ("D:\SIRIUS\Applications\Coake\Images\Fehlerbilder\Kamera2\*.bmp") Sleep (60000) RunWait ("C:\Documents and Settings\Administrator\Desktop\backup.bat") $file = FileOpen("G:\log.txt", 1) ; Check if file opened for writing OK If $file = -1 Then Exit EndIf FileWriteLine($file, "Data ultimului back-up: " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & @CRLF) FileClose($file) Sleep (900000) call ("backup") Endfunc Also I made another script to prevent the steal of the USB stick:#include <MsgBoxConstants.au3> Example() Func Example() ; Create a constant variable in Local scope of the filepath that will be read/written to. Local Const $sFilePath = "G:\check.txt" Local $iFileExists = FileExists($sFilePath) Sleep (60000) ; Display a message of whether the file exists or not. If $iFileExists Then Else ProcessClose ( "Coake.exe" ) MsgBox(48, "ATENTIE!!!", "Stick-ul USB destinat pentru backup a fost inlaturat!" & @CRLF & "Introduce-ti stick-ul in calculator iar apoi chemati un electrician/inginer de proces!" & @CRLF & "Dupa introducerea stick-ului, programul Coake poate fi pornit din nou!") EndIfThe problem is that after a period of time, I get the error from atachment.Is another way to make the loop? At the back-up script I used While 1 and Wend and is working but at "check USB stick" it doesn't working or I don't know for sure were to put "while 1" and "wend".Can you help me please?P.S. I use Windows 2000 and a old version of autoit. Edited July 23, 2015 by rony2006 Link to comment Share on other sites More sharing options...
SadBunny Posted July 23, 2015 Share Posted July 23, 2015 You call the function "backup" fro within the function "backup". That's a function calling itself, and that's called recursion. You can only do recursion a number of levels deep. But since you have a really long waiting time (900 sec), you don't notice it immediately. Here's a demonstration:$iLevel = 0 myRecursiveFunction() Exit Func myRecursiveFunction() $iLevel += 1 ConsoleWrite($iLevel & @CRLF) myRecursiveFunction() EndFunc ;==>myRecursiveFunctionThis will run for a certain number of levels, then reproduce that error you have there.The simplest fix would be to make the function non-recursive, in your case, something like this:#include <MsgBoxConstants.au3> While True backup() Sleep(900000) WEnd Func backup() FileDelete("D:\SIRIUS\Applications\Coake\Images\Fehlerbilder\Kamera1\*.bmp") FileDelete("D:\SIRIUS\Applications\Coake\Images\Fehlerbilder\Kamera2\*.bmp") Sleep(60000) RunWait("C:\Documents and Settings\Administrator\Desktop\backup.bat") $file = FileOpen("G:\log.txt", 1) ; Check if file opened for writing OK If $file = -1 Then Exit EndIf FileWriteLine($file, "Data ultimului back-up: " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & @CRLF) FileClose($file) EndFunc ;==>backupIt will do pretty much the same thing, only the long wait and the new function call have been moved out of the function (so it's not recursive any more). Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
rony2006 Posted July 23, 2015 Author Share Posted July 23, 2015 Thank you for the quick answer.I tested now on the computer and the loop is working ok.Have a nice day! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now