I’ve been trying to copy files from an old drive to a new drive. Problem is, the old drive has (I can only assume) some corrupted places on the disk, and any attempt to read from some of these files results in what seems to be some kind of endless loop. There are quite a few problem files sprinkled throughout the files I want to copy, and when it hits the first one, my application just sits there doing nothing until I stop it. I was hoping I could get around this by writing a custom program to recurse through the directories, copy the files one by one, and catch any errors that pop up on individual copy operations, but it never gets to the point of throwing an error–just sits there and sits there and sits there. The only way to stop this is to physically turn off the problem hard drive–can’t stop the program by trying to end the process or anything like that.
I’m somewhat puzzled as to how to proceed. Given that this kind of error is going to happen, is there any way to automate this process? Does anyone have any experience with this?
I guess you use the copy methods on the standard System.IO classes (Directory / DirectoryInfo / File / FileInfo)?
Have you tried to copy the files with a FileStream? To prevent those errors you can set a the ReadTimeout on the stream (stream.ReadTimeout). This way you get Exceptions when the Read() operation takes too long. And you should also get errors if a file can’t be opened.