2

I have to change file names a lot, but Windows won't let you change them when they're open. I know I can exit and rename the file after, or Save As with a different name, but this just seems like bad design.

Is anyone aware of a better workaround?

Tetsujin
  • 50,917

1 Answers1

2

Your premise is false. Files cannot be renamed if they are intentionally locked, a feature of many operating systems, including Linux and Windows, to prevent unpredictable results when trying to write to a file.

However, many applications, such as Notepad++ (NPP), can open a file read-only, not requiring a lock. Test this yourself: open a file in NPP and, with the file left open, rename it.

For your edification, you can peruse the Windows OpenFile constants, such as:

  • OF_READWRITE - Opens a file with read and write permissions.
  • OF_SHARE_DENY_NONE - Opens a file but allows other processes read and write acces.
  • OF_SHARE_EXCLUSIVE - Opens a file, denying both read and write access to other processes.