Jump to content

A way to detect file copy errors


 Share

Recommended Posts

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

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)

NEWHeader1.png

Link to comment
Share on other sites

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

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

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
Link to comment
Share on other sites

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

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
Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

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