0

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

asaf
  • 958
  • 1
  • 16
  • 38
  • I don't understand the point of copying a directory structure, deleting the original, and then renaming the copy to the same name as the original. But, whatever. If all you want to do is rename a single directory, then yes...that single operation is atomic at the file system level. What intermediate state did you think could occur? Your question isn't very clear. – Peter Duniho Apr 03 '17 at 05:42

1 Answers1

1

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.

Community
  • 1
  • 1
C. McCoy IV
  • 887
  • 7
  • 14
  • is Transactional file system automatic for windows server 2016 or do i need to set it up ? – asaf Apr 03 '17 at 11:50