Why do you still have to close files in order to move them to a different folder?

593 views

I’ve never understood why, even on Windows 10, that you have to close a file before moving it to a different folder. It seems like an archaic holdover from more primitive days. Why can’t this issue be fixed? After all, you can now attach an open file to an email, something you couldn’t do in Windows 95. It seems like it would be an easy enough thing for a computer to understand that you want to store something somewhere else now, even if it is open.

In: Technology

2 Answers

Anonymous 0 Comments

This is intentional.

The operating system knows which files still have running programs referencing them. Moving a file will invalidate the references. It isn’t enough to “notify” programs holding a reference to they file — a program might not be coded to handle such a notification. Therefore, Windows explicitly returns an error when trying to take an action that would interfere with a file reference.

Linux handles it differently. Linux allows the file operation to go through, but doesn’t actually do anything until all references are dropped. Once they’re dropped, the file is then deleted. This, in my opinion, can be worse, because it can result in file leaks when a program is incorrectly coded to forget to close files. You can call delete on a file as many times as you want and it won’t actually free the space until nothing has it open anymore.

I don’t have an answer why Microsoft decided to do it one way and Linux the other. It’s just what they decided. I consider both of these methods to be better than the third option, which is to just delete the file immediately and crash any other programs using it.

It’s probably impossible to ever change Windows file handling without breaking backwards compatibility with… everything.

Here is some more information about how Linux handles deletion https://stackoverflow.com/questions/2028874/what-happens-to-an-open-file-handle-on-linux-if-the-pointed-file-gets-moved-or-d

Anonymous 0 Comments

I don’t know if this is still the case, but old Mac OS would keep data read/write operations correctly wired up even if you moved the file. This could be used to get around early streaming protection where the video files were temporarily cached on disk. If you moved the video file out of that folder while it was still playing and you let it play to the end, the system would attempt to delete the cached video file, not find it at its original location, and just sort of shrug, and you’ve have the video saved locally.

This was a *long* time ago, though, and I don’t quite remember which version of Mac OS worked this way.