Windows: copying a file that is in the process of being written

windows

Here's some easy points for someone:

If I issue a command like copy * /destination in a folder containing a file that is being written to, will the partially written file be copied? Will it be ignored? Will copy throw an error?

Basically I have a script that copies files from a folder to a new location on a schedule, and there could be a case in which a new file is being written to the source folder when the script runs. I'm wondering what precautions I might need to take.

Edit: I should mention that the file will be coming in via SMB to a shared folder.

Best Answer

Either:

  1. The file will be locked and nothing will happen. It may crash your script if you don't have decent error handling.
  2. A copy of the file will be made in the state it was in at the instant the copy was initiated. Data written to the file after this instant will not be in the copied file. Think of it as a snapshot of sorts

As always, test test test, and move from there.