Sign in to follow this  
Followers 0
FrozenTeeth

What's wrong with my error checking?

5 posts in this topic

The below code moves reports to and archive directory. It also logs the move. The issue I have is the @error returns a zero as in my log file it say's failed to move report. Even thou when I look the file(s) has moved just fine!

;
;move reports for archive
;
Dim $filestomove
$filestomove = _FileListToArray($ReportsDirectory, "ilb*.rpa")
For $x = 1 To $filestomove[0]
    FileMove($ReportsDirectory & $filestomove[$x], $ReportsBackupDirectory, 1)
    If @error = 0 Then
        LogAction("Failed to move report: " & $ReportsDirectory & $filestomove[$x] & " to " & $ReportsBackupDirectory & $filestomove[$x] & " file already exists")
    Else
        LogAction("Moved report: " & $ReportsDirectory & $filestomove[$x] & " to " & $ReportsBackupDirectory & $filestomove[$x])
    EndIf
Next

From the help file:

FileMove

Moves one or more files

FileMove ( "source", "dest" [, flag] )

Parameters

source The source path and filename of the file to move. (* wildcards are supported)

dest The destination path and filename of the moved file. (* wildcards are supported)

flag [optional] this flag determines whether to overwrite files if they already exist:

Can be a combination of the following:

0 = (default) do not overwrite existing files

1 = overwrite existing files

8 = Create destination directory structure if it doesn't exist (See Remarks).

Return Value

Success: Returns 1.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Posible empty entry in you $filestomove array.(?)

It moves 6 files a day so I would think that $filestomove array is correct and working the way it should.

Share this post


Link to post
Share on other sites

Return Value

@Error: 1 = Path not found or invalid

2 = Invalid $sFilter

3 = Invalid $iFlag

4 = No File(s) Found

^^ from help file.

If @error = 0 Then
        LogAction("Failed to move report: " & $ReportsDirectory & $filestomove[$x] & " to " & $ReportsBackupDirectory & $filestomove[$x] & " file already exists")
    Else
        LogAction("Moved report: " & $ReportsDirectory & $filestomove[$x] & " to " & $ReportsBackupDirectory & $filestomove[$x])
    EndIf

this part of the code says if @error = 0 Eg: NO ERROR log action error...

looks like you need to put if @error <> 0 then

hope that solves it

-1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Maybe something like this:

If FileMove($ReportsDirectory & $filestomove[$x], $ReportsBackupDirectory, 1) Then
        LogAction("Moved report: " & $ReportsDirectory & $filestomove[$x] & " to " & $ReportsBackupDirectory & $filestomove[$x])
    Else
        LogAction("Failed to move report: " & $ReportsDirectory & $filestomove[$x] & " to " & $ReportsBackupDirectory & $filestomove[$x] & " file already exists. Error" & @error)
    EndIf

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
Sign in to follow this  
Followers 0