EdRoberts Posted November 20, 2008 Posted November 20, 2008 I've been struggling with an error check I'm performing during a simple FileMove. $process = FileFindFirstFile("*.txt") While 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename") FileMove($file, @YEAR & @MON & @MDAY & "/" & $name & ".txt", 8) MsgBox(0,"test", @error & " error code.") WEnd In this example, it doesn't matter if my FileMove is successful or if it fails because the file is already exists at the destination. Both return an error code of 0 (fail). Have a completely missed something as to how FileMove hands out error codes? Does adding the date variables in the string make this technically fail even if the file moves successfully?
CounterCraft Posted November 20, 2008 Posted November 20, 2008 I've been struggling with an error check I'm performing during a simple FileMove. $process = FileFindFirstFile("*.txt") While 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename") FileMove($file, @YEAR & @MON & @MDAY & "/" & $name & ".txt", 8) MsgBox(0,"test", @error & " error code.") WEnd In this example, it doesn't matter if my FileMove is successful or if it fails because the file is already exists at the destination. Both return an error code of 0 (fail). Have a completely missed something as to how FileMove hands out error codes? Does adding the date variables in the string make this technically fail even if the file moves successfully? filemove should be something like filemove ("c:/lol.exe", "c:/temp/lol.exe") if you want to make it complex then do filemove ($original, $newlocation) as for the rest... I'm still figuring out after I post this or someone who's better than be to post
toonboon Posted November 20, 2008 Posted November 20, 2008 Firstly, preferably use autoit tags, they have colour coding.. secondly, try setting the flag of filemove to overwrite, see what happens =) [right]~What can I say, I'm a Simplistic person[/right]
CounterCraft Posted November 20, 2008 Posted November 20, 2008 (edited) @YEAR & @MON & @MDAY & "/" & $name & ".txt", 8problem I see is that autoit can't locate this 2008 drive or folder you should use variable that represents new location and use date macro after-wiseare you using this statement correctly?If @error Then ExitLoopit should be If @error > 0 Then ExitLoop Edited November 20, 2008 by CounterCraft
EdRoberts Posted November 20, 2008 Author Posted November 20, 2008 (edited) Firstly, preferably use autoit tags, they have colour coding..secondly, try setting the flag of filemove to overwrite, see what happens =)Sorry about missing the autoit tag. The overwrite flag throws the same error code of 0. I also made the date a variable, as @countercraft had suggested, with no luck. The file DOES move successfully. It overwrites correctly. It creates the directory if it doesn't exist. All with no issues. Edited November 20, 2008 by EdRoberts
EdRoberts Posted November 20, 2008 Author Posted November 20, 2008 Let me simplify the whole expression:FileMove("A.txt", "B.txt", 1) MsgBox(0,"test", @error)Still returns 0. Does the return from FileMove even utilize @error?
youknowwho4eva Posted November 20, 2008 Posted November 20, 2008 From help file : Success: Returns 1. Failure: Returns 0 if source cannot be moved or if dest already exists and flag=0. so if the file already exists the flag is still 0. Filemove("A.txt","new\B.txt",9) msgbox(0,"test",@error) should return 1 the first time it is used. and 0 afterwards. If I'm not mistaken Giggity
CounterCraft Posted November 20, 2008 Posted November 20, 2008 (edited) $process = FileFindFirstFile("*.txt")If $process= -1 Then MsgBox(0, "Error", "No text files available") ExitEndIfWhile 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename or type exit to terminate the program") if $name = "exit" then Exit EndIf FileMove($file, $file & @YEAR & @MON & @MDAY, 9) MsgBox(0,"test", @error& " error code.")WEndThe destination directory must already exist, except using with flag value '8'.For instance the combined flag '9' (1 + 8) overwrites the target file and prechecks for the destination directory structure and if it doesn't exist creates it automatically.Some file attributes can make the overwriting impossible.whatever you're doing.... destination information is incorrect....$process = FileFindFirstFile("*.txt")If $process= -1 Then MsgBox(0, "Error", "No text files available") ExitEndIfWhile 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename or type exit to terminate the program") if $name = "exit" then Exit EndIf FileMove($file, "C:/", 9) MsgBox(0,"test", @error& " error code.")WEnd^result wasNew Text document.txt20081120New Text Document (2).txt2008112020081120after two run \O_o/ Edited November 20, 2008 by CounterCraft
EdRoberts Posted November 20, 2008 Author Posted November 20, 2008 (edited) From help file : Success: Returns 1. Failure: Returns 0 if source cannot be moved or if dest already exists and flag=0. so if the file already exists the flag is still 0. Filemove("A.txt","new\B.txt",9)msgbox(0,"test",@error)should return 1 the first time it is used. and 0 afterwards. If I'm not mistakenEXACTLY. This should return a 1 instead of a 0. The source file CAN be moved and the dest file does NOT already exist. After the script runs, A.txt becomes B.txt with no problems. Why is AutoIt returning a 0 error code instead of a 1? Edited November 20, 2008 by EdRoberts
CounterCraft Posted November 20, 2008 Posted November 20, 2008 hmm... moving into z: drive still shows 0 error code.... that is mystery
November Posted November 20, 2008 Posted November 20, 2008 (edited) hmm... moving into z: drive still shows 0 error code.... that is mysteryHi there, I was testing your script and i got the same error. I dig deeper and changed a little bit your code... some minor changes. An i got to this and the error code changed I'm divided : - EDIT - After Valik Post 1 - The error is from another command. 2 - It's a bug! 3 - Doesn't send @error, so read very carefully including me - EDIT - $process = FileFindFirstFile("*.txt") $date = @YEAR & @MON & @MDAY While 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename") $copy = FileMove($file, $date & "/" & $name & ".txt", 9) MsgBox(0,"test", $copy & " error code.") WEnd My troubleshoot code : $process = FileFindFirstFile("*.txt") $date = @YEAR & @MON & @MDAY While 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename") $error = @extended MsgBox(0,"test", $error & " error code.") FileMove($file, $date & "/" & $name & ".txt", 9) $test = @extended MsgBox(0,"test", $test & " error code.") WEnd Cheers Enjoy Edited November 20, 2008 by november Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
EdRoberts Posted November 20, 2008 Author Posted November 20, 2008 (edited) Hi there, I was testing your script and i got the same error. I dig deeper and changed a little bit your code... some minor changes. An i got to this and the error code changed I'm divided : 1 - The error is from another command. 2 - It's a bug! $process = FileFindFirstFile("*.txt") $date = @YEAR & @MON & @MDAY While 1 $file = FileFindNextFile($process) If @error Then ExitLoop $name = InputBox("Enter filename","Enter filename") $copy = FileMove($file, $date & "/" & $name & ".txt", 9) MsgBox(0,"test", $copy & " error code.") WEnd Cheers Enjoy I think I've pretty much resigned this to be a bug as well. When even the basic command throws the wrong error code you wonder. The 3.2.6 update made a bug change to FileMove as it was returning a 1 even in an failure. It's certainly possible an update since then broke it again. UPDATE: I just went back and reread your solution. I missed assigning a variable to the filemove to extract the error code. This was where I was falling. FileMove doesn't change the @error macro, but returns within that line of the expression. Thanks! I'll go beat my head against my desk. Edited November 20, 2008 by EdRoberts
CounterCraft Posted November 20, 2008 Posted November 20, 2008 (edited) what is @error use for?is it only file move that does not toggle @error or every other statement will be same as what novemeber posted?EDITok.... I guess file move doesn't set error automatically....run("asdasdas")msgbox (0, "asd", @error)Success: The PID of the process that was launched. Failure: Returns 0 and sets @error to non-zero. Edited November 20, 2008 by CounterCraft
Valik Posted November 20, 2008 Posted November 20, 2008 (edited) FileMove() does not set @error. Read the damn documentation. ESPECIALLY read the documentation before you open tickets (#695 because guess what? You look pretty damn stupid reporting a "bug" when all you had to do was spend 15 seconds reading.Edit: By the way, my statement applies to several of you who all neglected to bother reading the documentation. The code was obviously wrong. Edited November 20, 2008 by Valik
November Posted November 20, 2008 Posted November 20, 2008 FileMove() does not set @error. Read the damn documentation. ESPECIALLY read the documentation before you open tickets (#695 because guess what? You look pretty damn stupid reporting a "bug" when all you had to do was spend 15 seconds reading.Edit: By the way, my statement applies to several of you who all neglected to bother reading the documentation. The code was obviously wrong.My mother always said to read more Sorry about that false bug!Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
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