Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently added two 2TB WD Caviar Black SATA drives to an external enclosure with USB 2.0 . Since then I have to deal with occasional file corruption when I copy files with Explorer from my local C: drive to the external drives. I either end up with files that cannot be read anymore, or with files that can be read but cannot be copied once they are on one of the external HD's. All drives have been tested and are okay. Did some googling now and found various hints on the web that it might be a problem with the shell of my Vista Home Premium 32bit (all updates applied).

To circumvent this file corruption I am looking for the safest way to copy files from one NTFS file system to another (preserving all file properties), including a CRC32 check - if possible without involving the Shell. Can anyone point me to a code snippet which shows how to do that in Delphi 2007 Pro?

share|improve this question

migrated from Apr 14 '11 at 6:28

This question came from our site for professional and enthusiast programmers.

Are you properly ejecting the drive before detaching it? I've got the same version of Vista on a desktop, and have never had a problem with copying via USB to external drives. – Ken White Apr 14 '11 at 1:12
Ken, both drives are properly mounted and installed in an external Rosewill enclosure, which is permanently connected to my desktop. I just turn the enclosure on and my system recognizes both drives immediately. I've never had problems with file copies to external drives either before, but various reports on the web pointed to some unexpected and buggy behaviour of the Windows shell once UAC has been turned off. That's the case on my system. Thanks! – Phil Apr 14 '11 at 1:25
@Phil: That isn't what I asked. :) I asked if you were properly ejecting the drives before turning them off or disconnecting them. The process of ejecting (AKA "Safely Removing Hardware") flushes file buffers and prepares the file system prior to the device's disconnect. Turning the drive power off without safely removing them could corrupt data because the disk cache isn't completely flushed (both the OS's cache and the internal disk cache need to be fully written before power-down or removal). – Ken White Apr 14 '11 at 1:34
Ooops, sorry - yes, I eject the hardware before turning it off. The corrupted files occur randomly by the way, and I usually only find out when I compare folder sizes. – Phil Apr 14 '11 at 1:38
@Phil: I have a WD SATA connected to my desktop (1TB WD Elements SATA/USB 2.0, Vista 32 Home Premium) that does a weekly backup. It's not powered on/off; it just stays connected and powered up while the system is on. I've never experienced corruption of any files, and I've verified restores from the backups. I really think you have a hardware issue here. – Ken White Apr 14 '11 at 1:57

Your drives are probably formatted with NTFS.

A drive can only be formatted for NTFS if it is not marked for "quick removal".

Which means that you should properly shutdown your machine before turning off or removing your NTFS drive.

For copy, you can use RoboCopy; it does not have a verify though, but it has a very fast backup mode (which you can use when you are logged on as Administrator and have elevated to your Administrator token).

XXCOPY has verify, and a good RoboCopy/XXCOPY comparison is here.

For my backups, I use a RAID system with active checking. That means it regularly checks all the RAID volumes for integrity. Not cheap, but worth the money.

share|improve this answer
Jeroen, yes my drives are all NTFS formatted, but that shouldn't be the problem. The file corruption occurs only randomly, and also in different places all the time. I used Robocopy in the past, but switched to SyncToy and RichCopy. The latter two usually do their job very good, but I need some CRC verification which is why I want to write my own application. Thanks for the hints though! – Phil Apr 14 '11 at 3:06
XXcopy also has occasional problems with corruption of large files, and unfortunately its internal verification routine does not detect that. I suggest not relying on it for copying anything important. – moz Apr 14 '11 at 5:27

In case someone is interested: I found some interesting Delphi code on Earl F. Glynn's site at

share|improve this answer

The file corruption disappeared since I re-enabled UAC on my system. I've read reports about this before (although they were very vague), and it seems as if it did the trick. Thanks again for all responses! Much appreciated.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .