Reputation: 976
I am working in C# in visual studio.
I am using the command Directory.Move
I have an operational folder and i sometimes need to replace it.
what i do is to create a backup folder with the new content in the same directory the operational folder is, delete the operational and rename the folder.
if both folders (operational and backup) exists its ok because i know to read from the backup first.
BUT after deleting the operational and rename the backup folder to operational can there be a situation (if restart occures) that only part of the backup files / folders will be be in the new operational folder, or is move folder is atomic operational.
I need to operational to be successful meaning the operational folder contains everything, or failed to rename, BUT NO SOMETHING IN BETWEEN
Upvotes: 0
Views: 900
Reputation: 897
File operations are already atomic at the file system level under NTFS (Windows Vista+).
See this for details: Atomic file copy under .NET
For WinXP and below, it's like you thought.
Upvotes: 1