Jump to content

Filemove returning code 0 on success OR fail?


 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@YEAR & @MON & @MDAY & "/" & $name & ".txt", 8

problem I see is that autoit can't locate this 2008 drive or folder :mellow:

you should use variable that represents new location and use date macro after-wise

are you using this statement correctly?

If @error Then ExitLoop

it should be

If @error > 0 Then ExitLoop

Edited by CounterCraft
Link to comment
Share on other sites

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. :mellow:

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 by EdRoberts
Link to comment
Share on other sites

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

Link to comment
Share on other sites

$process = FileFindFirstFile("*.txt")

If $process= -1 Then

MsgBox(0, "Error", "No text files available")

Exit

EndIf

While 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.")

WEnd

The 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")

Exit

EndIf

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

New Text document.txt20081120

New Text Document (2).txt2008112020081120

after two run \O_o/

Edited by CounterCraft
Link to comment
Share on other sites

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

EXACTLY. 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 by EdRoberts
Link to comment
Share on other sites

hmm...

moving into z: drive still shows 0 error code.... that is mystery

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

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

Link to comment
Share on other sites

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. :mellow:

Edited by EdRoberts
Link to comment
Share on other sites

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?

EDIT

ok.... 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 by CounterCraft
Link to comment
Share on other sites

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 by Valik
Link to comment
Share on other sites

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

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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...