Jump to content

Recommended Posts

Posted

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?

Posted

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?
Posted

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.

Posted

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?

Posted (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 by dabus
Posted

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.

Posted (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 by dabus
Posted

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.

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
  • Recently Browsing   0 members

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