How to know that the file is complete, copy

Im using ReadDirectoryChangesW to spy on a folder, if Im copying a large file to a folder, I can receive several FILE_ACTION_MODIFIED messages, it seems every time the windows write a large fragment of the file, you get a file change notification for every time I tried to use CreateFile API to check whether a file can be opened by AP or not, but sometime some files are always blocked by another access point, for example, if you open Outlook, PST will be updated, but my AP cannot access it, we must start the shadow save To open it. So my question is: how do I know if the file is finished copying?

+2
source share
3 answers

This is a very hacky decision, but in a very hairy situation, you can run a polling cycle to check the size (or modified date) of the file. If this does not change for a while, you can safely assume that the file has finished copying.

EDIT: This is not an optimal solution in the middle case, but keep in mind that in the case of OP, the best solutions are excluded from problematic constraints. Think about this before thinking about downvoting.

+1
source

When you are polling for file size, do not use _stat/_stat64 . Instead, open the file every time you need and call _filelengthi64 to get the file size. The file size returned by _stat64 is not updated by the Windows operating system in real time. In addition, having the ability to open the file, you are testing to make sure that all long copy operations are complete.

0
source

Windows provides an API for monitoring directory content updates. You can use the generated event to detect a new file, but remember that this event does not necessarily mean that the file has not yet been released.

C ++ native specifications and code examples:

http://msdn.microsoft.com/en-us/library/aa365261 (VS.85) .aspx

.net:

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

0
source

All Articles