1

I have groups of files that need to be batch renamed from time to time. I don't want to rename any of them unless it can be asserted that all can be renamed from one to the other. Is there some kind of assertion method for doing this, or will I have to write my own?

tshepang
  • 12,111
  • 21
  • 91
  • 136
AaronF
  • 2,841
  • 3
  • 22
  • 32
  • 2
    You *could* use Windows' Transactional File System to do this as an atomic operation, however the code for that is rather tricky as there is no .NET support for this out-of-the-box. – vcsjones Jul 31 '14 at 16:20
  • Yup, not possible in general. [Transactional NTFS](http://msdn.microsoft.com/en-us/library/aa365738%28VS.85%29.aspx) should be able to get the job done on Vista+ systems - one of the example use cases is consistency with renames. – nobody Jul 31 '14 at 16:23
  • See also my answer on how to get file permissions: http://stackoverflow.com/a/22020271/880990 – Olivier Jacot-Descombes Jul 31 '14 at 16:41

1 Answers1

1

Transactional NTFS can do that. There are .NET wrappers for that.

If you don't want to use that consider opening all files in exclusive mode before you start the renaming. That gives you assurance that there was a point in time where each of the files was unused. Of course, those files can be opened right after your check so it is only a heuristic.

usr
  • 168,620
  • 35
  • 240
  • 369
  • Thanks. Could you provide any specifics on what I'm looking for here exactly? I'm not familiar with Transactional NTFS or its wrappers. – AaronF Jul 31 '14 at 16:28
  • http://msdn.microsoft.com/en-us/library/windows/desktop/bb968806(v=vs.85).aspx Can't do more than to point you to the documentation and to search engines. The information is all there. Just enter "Transactional NTFS .NET". – usr Jul 31 '14 at 16:37
  • This library may be helpful : http://txfnet.codeplex.com/ but I don't know if it provides "rename" feature. – AFract Jul 31 '14 at 18:11