Sign in to follow this  
Followers 0
welby345

A way to detect file copy errors

13 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

FileCopy ( "source", "dest" [, flag] )

[snip]

Failure: Returns 0.

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

@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 ?:lmao:


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Thanks. I appreciate the help. New to Autoit, but seems really powerful.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Welcome...

I am sure the next one wont be so easy also...lol

BTW.. Welcome to the Autoit Forums

8)


NEWHeader1.png

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#10 ·  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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#12 ·  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

Share this post


Link to post
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.

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