We have an application that stores files in a temporary location until the user decides to finalize their transaction. The temp directory is unique for each transaction. Once they do finalize, the files are moved from the temp location to a final location, which is also unique for each transaction. This is all working without any issues.
I'm rather surprised, but when searching Google and SO, we were unable to find any topics on which is generally considered a best practice:
As these decisions typically rely on a number of factors, I should note the following conditions:
I think the biggest issue is not speed but rather: what happens on a move error?
I'm going to use the information in LukeH's answer rather than repeating it here.
The behaviour of MoveFile
for a directory move should be appropriate for if it fails to move a single file. If you use a per file move, then you have to handle the error conditions yourself in an appropriate manner. This requires some careful thought.
Note that the documentation of MoveFile
specifies that:
The one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.
That might or might not be an issue for you and reason to use a per-file Move. The Directory.Move
documentation explicitly mentions this (and the reference source for Directory.Move
explicitly checks for source and destination having the same root).