welby345 Posted October 13, 2006 Share Posted October 13, 2006 I am writing a script to copy a file from a cd-rom to a disk. I want to detect a file copy error. I don't care if it's after the copy, or during the copy...as long as I detect the error. Any ideas on teh best way to do this using autoit? Link to comment Share on other sites More sharing options...
this-is-me Posted October 13, 2006 Share Posted October 13, 2006 (edited) FileCopy ( "source", "dest" [, flag] ) [snip] Failure: Returns 0. Edited October 13, 2006 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
MadBoy Posted October 14, 2006 Share Posted October 14, 2006 @this-is-me.. kinda obvious but.. what if only 1 of 999 files won't be copied? How to know this file wasn't copied? And/or resulted error ? My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
this-is-me Posted October 14, 2006 Share Posted October 14, 2006 In that case, you must FileCopy each individually. You should start by getting a list of each file in the directory you need to copy, and then loop through each copy with error checking. That is the only solution that comes to mind immediately. Who else would I be? Link to comment Share on other sites More sharing options...
welby345 Posted October 16, 2006 Author Share Posted October 16, 2006 Thanks. I appreciate the help. New to Autoit, but seems really powerful. Link to comment Share on other sites More sharing options...
Valuater Posted October 16, 2006 Share Posted October 16, 2006 also you could check the amount of files "to be copied" then check the amount of files "that were copied" #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray(@DesktopDir) If (Not IsArray($FileList)) and (@Error=1) Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList $FileList[0] will return the number of files in the folder 8) Link to comment Share on other sites More sharing options...
welby345 Posted October 16, 2006 Author Share Posted October 16, 2006 That's actually a good idea Valuater. That would make sure everything was copied as it should be, and give me one more sanity check. Thanks for the ideas. I'm, sure I'll be back with more questions. Maybe my next questions won't be so easy. Link to comment Share on other sites More sharing options...
Valuater Posted October 16, 2006 Share Posted October 16, 2006 Welcome... I am sure the next one wont be so easy also...lol BTW.. Welcome to the Autoit Forums 8) Link to comment Share on other sites More sharing options...
welby345 Posted October 19, 2006 Author Share Posted October 19, 2006 I hate to bring this up again, but I cannot get my code to work. This is what I have written. Dim $cdrom $cdrom = DriveGetDrive("CDROM") DirCreate("C:\cdromtest") If Not FileCopy($cdrom[1] & "testfile1.dat", "c:\cdromtest") Then MsgBox (0,"","Error on file 1 copy.") Else MsgBox(0,"","No error on file copy 1") EndIf I get the first message evertime. The directory gets created, and the file gets copied, but I always get the first message. I have treid removing the file so it's not there to copy, and I still get the first message. Any ideas what I'm doing wrong? Link to comment Share on other sites More sharing options...
dabus Posted October 19, 2006 Share Posted October 19, 2006 (edited) You need $cdrom[1] & "\testfile1.dat"... Don't you want to check if the file exists first? And I think you should use xcopy or robocopy, if you got rewriteable cds with modified data, since doing all the stuff with autoit can be some work: getting all the files -- recursive if needed check if you need to copy (checksum/size...) copy the file(s) check what's wrong if copy failed (like diskspace...) Edited October 19, 2006 by dabus Link to comment Share on other sites More sharing options...
welby345 Posted October 20, 2006 Author Share Posted October 20, 2006 I don't think you understand what I'm doing. I'm copying from the cd to the hard drive. I just want to make sure that if the copy fails, that a msg box pops up telling you so. The file always copies fine, so I don't think it's the missing slash. The problem is that even if the file is not there to copy, the message box does not pop up. I want to detect the copy failyre only. Link to comment Share on other sites More sharing options...
dabus Posted October 20, 2006 Share Posted October 20, 2006 (edited) I could swear DriveGetDrive("CDROM") returns sth like f: , so filecopy f:testfile.dat is not a valid path. Please look at the feedback Consolewrite/MsgBox gives you if you add a debug-line... I'm writing this under linux, so it's not tested, but it should work... If you want to copy all files, you could make a loop: Dim $cdrom $cdrom = DriveGetDrive("CDROM") DirCreate("C:\cdromtest") ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile($cdrom[1] &"\*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $test=FileCopy($cdrom[1]&'\'&$file, "c:\cdromtest") if $test=0 Then MsgBox (16, 'Copy', 'Copy failed at'&@CR&$file) WEnd ; Close the search handle FileClose($search) Edited October 20, 2006 by dabus Link to comment Share on other sites More sharing options...
welby345 Posted October 23, 2006 Author Share Posted October 23, 2006 I re-installed Autoit, re-compiled my script, and I finally got it to work. I didn't have to change anything, but I am going to add the \ anyway to be safe. I was beginning to feel real stupid there for a minute. Thanks to everyone for your help. 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