Cagurtay
Cagurtay

Reputation: 45

How to know if copying is finished in Windows?

I am writing a tool that listens a location, preferably remote location, and if a new folder or file created, it will download it to a local location.

Currently I am listening the remote folder with FileSystemWatcher, when a new folder/file created, I start a timer and if timer reaches X minutes it starts to copy it to local. Creating a new folder or file in "watched " folder triggers FileSystemWatcher.Changed but it sometimes fail if there are a lot of sub-directories and if there is a large file copying to watched folder, it only detects it when copying started and my timer can finish until it is finished.

So: I have 3 remote computers/locations, A,B,C

A starts to copy some folders/files to B and C listens to B .

How can C check if A is finished copying with or without FileSystemWatcher? I don't want to constantly compare B and C and copy rest of the files.

I checked other questions but they don't answer or I already did implement those solutions. 1, 2,3

Upvotes: 3

Views: 1341

Answers (1)

No Refunds No Returns
No Refunds No Returns

Reputation: 8356

I think you are asking about the system change journal. That said, there will always be cases where the file is in use, has been deleted, updated, etc. between the time you detect you need to copy it and when you really start copying. Here's an old but accurate article that can give you more details.

http://www.microsoft.com/msj/0999/journal/journal.aspx

From the article abstract:

"The Windows 2000 Change Journal is a database that contains a list of every change made to the files or directories on an NTFS 5.0 volume. Each volume has its own Change Journal database that contains records reflecting the changes occurring to that volume's files and directories."

Scroll down to the heading ReasonMask and ReturnOnlyOnClose

Upvotes: 5

Related Questions