Using Windows API, is it possible to rename a file that's open in another process without FILE_SHARE_DELETE
permissions?
I thought it's impossible based on CreateFile
docs that say:
Note: Delete access allows both delete and rename operations.
Consistent with that, renaming through regular rename
in the end-user command prompt, I often encountered The process cannot access the file because it is being used by another process.
; a similar error happens with renaming through end-user GUI and through python's os.rename
.
However, this highly-upvoted answer seems to state the opposite:
Deleting will fail if any other process has the file opened without delete sharing, renaming is never a problem.
And it's not just a minor point; the entire answer depends on that statement: it only solves the OP problem if renaming wouldn't fail when delete would.
What am I missing?
Note: If it matters, I am referring to Windows 10, using C++ API (which I assume is strictly more powerful than C# API).
Edit: moved the code snippet to a new question.