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

595 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

You are viewing 1 out of 2 answers, click here to view all answers.