Jump to content
Sign in to follow this  
RooperGee

FileCopy and bad CDs

Recommended Posts

RooperGee
Posted (edited)

I have a script that populates an array with the paths to certain files on a CD disc and their intended destinations.  I do a simple For-Next loop to go through the array and perform a filecopy command to copy them to a location on the hard drive.  My issue is sometimes CDs are bad and if I try to FileCopy a file that can't be read my script just hangs as it forever tries to access the file on the CD drive.  Any suggestions on how to have a timeout if the filecopy operation is taking too long?

...the important bit:

For $i = 1 to $aFiles[0][0]
    filecopy($aFiles[$i][0], $aFiles[$i][1])
Next

Thanks!

Edited by RooperGee

Progress lies not in enhancing what is, but in advancing towards what will be. - Kahlil Gibran

Share this post


Link to post
Share on other sites
xcaliber13

RooperGee,

                I would try putting in a FileOpen first.  Something like this:

For $i = 1 to $aFiles[0][0]

Local $hFileOpen = FileOpen($aFiles[$i][0], $FO_READ)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file." 10)
    Else
         filecopy($aFiles[$i][0], $aFiles[$i][1])
    EndIf
 
Next

I have not tested this but might get you going in the right direction.   Also put a FileClose in there.

Share this post


Link to post
Share on other sites
RooperGee
Posted (edited)

Thanks for the suggestion xcaliber13!  I tried it out and the script still just hangs while Windows tries to access the bad file on the CD rom drive.

Edited by RooperGee

Progress lies not in enhancing what is, but in advancing towards what will be. - Kahlil Gibran

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

Unfortunately non-production home burn CDs don't last forever.  I also wonder why you want to copy things from such a slow medium. 

 

I do have an idea though, you could write a separate script that monitors those events to see what's going on and manage it that way

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
RooperGee

Hello Earthshine - CDs are still used a lot in medical imaging for patients to bring their radiology exams to their doctors or hospital visits.  I write a lot of code manipulating medical image data and I recently was working on a better method for importing CD data into our server repositories.  I'm looking to be able to recover from scenarios where we can only read part of the CDs because some of the data is bad.  I had considered writing and compiling a bit of code to just start the copy attempt and then I could monitor my own copy process to see if it has froze and then I could ProcessClose it, flag it as an error and move on to the next one.  I was just hoping for a way to do it all in one script.  

  • Like 1

Progress lies not in enhancing what is, but in advancing towards what will be. - Kahlil Gibran

Share this post


Link to post
Share on other sites
Earthshine

yeah. sorry


My resources are limited. You must ask the right questions

 

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  

×