Search code examples
delphidelphi-2007diskactivity-monitor

Detect disk activity in Delphi


I'm using Delphi 2007.

I am copying files to a remote drive. When the copying ends, I shutdown/standby the machine. It can happen that some files don't get copied from buffer to disk, and the remote disk gets disconnected, so the backup is not completed. I need to detect disk activity on that disk to properly be able to take the close action on the machine.

Is there a way to detect disk activity in this scenario?


Solution

  • (Please move the additional information from the comment to your question.) AFAIK there is no Windows API to tell whether all data has been written to disk.

    What you are looking for is the Windows equivalent of the Unix sync command. You could run this tool from your program. Please read the information on the linked page, this requires administrative rights, and even so it may not be enough to be sure - some disk drives have a firmware that tells the OS that all writes have completed, when in fact they have not, and unwritten data is still in the on-disk-cache. You should better add a delay after your copy action has finished, to be on the safe side.