niranjan8shh Posted December 8, 2003 Share Posted December 8, 2003 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 Link to comment Share on other sites More sharing options...
niranjan8shh Posted December 8, 2003 Author Share Posted December 8, 2003 If FileExists($mozkonf & "\mozilla.bmp") ThenThanks 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.regardsniranjan Link to comment Share on other sites More sharing options...
niranjan8shh Posted December 8, 2003 Author Share Posted December 8, 2003 $ 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")EndIfFileCopy ("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 !")EndIfExit--- end code ---If file really exists at source dir, it does report existence and does get copied and get reported as success.BUTIf 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 8, 2003 Developers Share Posted December 8, 2003 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
niranjan8shh Posted December 8, 2003 Author Share Posted December 8, 2003 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. JosThanks 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 , 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. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 8, 2003 Developers Share Posted December 8, 2003 niranjan , I copied your Filecopy statement without checking its validity... sorry 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
niranjan8shh Posted December 9, 2003 Author Share Posted December 9, 2003 Just wanted to share with you that the filecopy returns its "returncode" into a variable .. not into @ERROR..JosJdeB, 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.zipfrom Autoit3 help fileMacros======Read only variables with special values. Similar to the AutoIt v2 "A_DAY" type variables. e.g. @MyDocuments, @StartupCommonFull 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" ====== 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