Sign in to follow this  
Followers 0
niranjan8shh

FileExists / FileCopy errors

7 posts in this topic

Hi,

I am puzzled by the follwoing:

------ start code -----

$mozkonf = "I:\netconf\mozilla"

If FileExists("$mozkonf\mozilla.bmp") Then

MsgBox(0, "Existence - Yes", "File exists")

Else

MsgBox(0, "Existence - NO", "File not found")

EndIf

FileCopy("$mozkonf\mozilla.bmp", "C:\TEMP\TEST\mozilla.bmp")

If @ERROR == 0 Then

MsgBox(0, "Copied - Yes", "File copied")

Else

MsgBox(0, "Copied - No", "File not copied")

EndIf

Exit

------ end code -----

First I am getting "File not found" and then "File copied" message.

My first questions is:

How can FileCopy succeed if FileExists failed to find the file?

(I am sure that the path is correct, and the file exists, and I have all the necessary access.)

Second, the file doesn't get copied, but the errorlevel after FileCopy command is 0. Which would mean the command completed successfully.

The behaviour doesn't change even if I replace the network path with local exact path.

The OSes on which this is tested is XP Pro and W2K.

Anyt help and hints are appreciated.

regards

niranjan

Share this post


Link to post
Share on other sites



If FileExists($mozkonf & "\mozilla.bmp") Then

Thanks Larry, that did the trick on FileCopy as well.

However I wonder why did it keep telling "File Copied" and did not complain of any syntax errors.

regards

niranjan

Share this post


Link to post
Share on other sites

$ is some kind of wild card... maybe that has sumpin' ado wid it.

Hi again, I tested the code without $ but still incorrect filecopy success report:

--- start code ---

If FileExists("E:\AUTOIT\SOURCE\mozilla.bmp")

MsgBox(0, "Existence", "file exists")

Else

MsgBox(0, "Existence", "file does not exist")

EndIf

FileCopy ("E:\AUTOIT\SOURCE\mozilla.bmp", "E:\AUTOIT\DEST\mozilla.bmp" ,1)

If @ERROR == 0 Then

MsgBox(0, "Copied - Yes", "Filecopy command returned 0=Success !")

Else

MsgBox(0, "Copied - No", "Filecopy command returned 1=Fail !")

EndIf

Exit

--- end code ---

If file really exists at source dir, it does report existence and does get copied and get reported as success.

BUT

If file does not exist at source, it gets corrrectly reported by FileExists command as not existing,

AND it gets reported by FileCpy command as "Filecopy command returned 0=Success !"

Perhaps FileCopy command reports errors differently.

niranjan

Share this post


Link to post
Share on other sites

niranjan ,

I see the same issue that it returns an 0 even when it didn't copy anything.

It returns a 1 if an error occurs.

Think the code should be something like when you want to test the returncode:

$rc = FileCopy("$mozkonf\mozilla.bmp", "C:\TEMP\TEST\mozilla.bmp")

If $rc = 0 Then

MsgBox(0, "Copied - Yes", "File copied")

Else

MsgBox(0, "Copied - No", "File not copied")

EndIf

Exit

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

niranjan ,

I see the same issue that it returns an 0 even when it didn't copy anything. It returns a 1 if an error occurs.

Jos

Thanks JdeB.

I am a newbie, aand code you have suggested is of course more neat.

Re errorcode:

I would like to hear from the gurus in this forum :whistle: , but it looks like a bug.

In addidion is also the issue of getting no syntax error when I tried

If FileExists("$mozkonf\mozilla.bmp") Then

and Larry corrected it to

If FileExists($mozkonf & "\mozilla.bmp") Then

and it started to work, which BTW seems to be the case in your line too

$rc = FileCopy("$mozkonf\mozilla.bmp", "C:\TEMP\TEST\mozilla.bmp")

regards, niranjan.

Share this post


Link to post
Share on other sites

niranjan ,

I copied your Filecopy statement without checking its validity... sorry :whistle:

Just wanted to share with you that the filecopy returns its "returncode" into a variable .. not into @ERROR..

You are correct that Filecopy doesn't return a 1 if theres nothing to copy...don't know why.....thats for the developers to answer.

As far as your syntax error question: I assume that "$mozkonf\mozilla.bmp" could be a valid filename. So is not really wrong... just doesn't exist.

cya

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

Just wanted to share with you that the filecopy returns its "returncode" into a variable .. not into @ERROR..

Jos

JdeB,

My understanding is that @ERROR is just an internal Au3 Macro for retruncode. A full list of Internal Macros is in the helpfile, and a full test of all of these Macros is done by van_renier availabel at:

http://groups.yahoo.com/group/AutoItList/files/AU3/SCRIPTS/

FULL Test of Auto-it Switches and innate variables.zip

from Autoit3 help file

Macros

======

Read only variables with special values. Similar to the AutoIt v2 "A_DAY"

type variables. e.g. @MyDocuments, @StartupCommon

Full list:

"error",

"SEC", "MIN", "HOUR", "MDAY", "MON", "YEAR", "WDAY", "YDAY",

"ProgramFilesDir", "CommonFilesDir",

"MyDocumentsDir", "AppDataCommonDir", "DesktopCommonDir", "DocumentsCommonDir", "FavoritesCommonDir",

"ProgramsCommonDir", "StartMenuCommonDir", "StartupCommonDir",

"AppDataDir", "DesktopDir", "FavoritesDir", "ProgramsDir", "StartMenuDir", "StartupDir",

"Computername", "WindowsDir", "SystemDir",

"SW_HIDE", "SW_MINIMIZE", "SW_MAXIMIZE", "SW_RESTORE", "SW_SHOW",

"ScriptFullPath", "ScriptName", "ScriptDir", "WorkingDir",

"OSType", "OSVersion", "OSBuild", "OSServicePack",

"AutoItVersion", "IPAddress1", "IPAddress2", "IPAddress3",

"IPAddress4", "CR", "LF", "CRLF", "DesktopWidth", "DesktopHeight"

======

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