5
0
When you open a text file in Notepad on Windows, you can move the source file to the Recycle Bin or even permanently delete it. The same is true for WordPad. Why is it that Windows doesn't give you a warning, complaining about file being open in another program?
However, if the same file is open in Word, and you try to moved the source file to the recycle bin or delete it permanently, Windows does give you a warning. The message itself can be a warning type of message, telling you that some (often unknwon) program has the file open. In case of Word 2013 on Windows 8.1 this is an info message, telling you exactly what program (Word) has the file open.
Why is that? Why is it that you can A) delete the source file while it's open in a program, and B) continue working on the document after the file has been deleted? Why is the behavior different in Notepad and WordPad from that of Word?
The first case behavior exists in Paint too. You can delete a bitmap file while it's open in Paint and continue working. But when you try to save it you get prompted for file location to save it to. With Notepad, it directly saves it to the same location that the original file was stored in and gives it the same name. Notepad doesn't prompt you for that.
I have not tested this on Windows 7, Vista, or XP. However, I would expect the behavior to be exactly the same, and so the question would probably apply to those systems as well.
2It's all about whether the program holds the file open while you edit it or not. Often they don't; they read a copy into memory and drop the file connection while you edit it. When you go to save it, it creates a new connection to the file handle. This is up to the program, not Windows. – Ƭᴇcʜιᴇ007 – 2014-12-16T19:27:11.503
So in this case, Word holds the original file open; Notepad does not? But Word makes a hidden copy of the original file when you open it. As some kind of temporary file. Isn't that the file Word is saving changes to? And then on exit, it merges the changes with the original file and discards the temporary file? If so, it should be possible to delete the original file while open in Word. – Samir – 2014-12-16T19:42:22.197
It's because Word is trying to track changes while you (or anyone) are editing it, and if two people made changes, and then it merged each user files back in, only the changes made by the last editor to save would stick. Notepad on the other hand (for example) doesn't care. :) – Ƭᴇcʜιᴇ007 – 2014-12-16T19:45:36.033
I'm rather surprised that notepad allows you to delete or move the file while it is open, but the application controls that, and in notepads case, its such a simple program that it doesn't attempt any concurrency control, and opens the file in read mode, and then loads it memory, releasing the read lock. For more info on whats going on with other files, see this: http://superuser.com/questions/848782/moving-files-from-one-location-to-another-while-they-are-being-used/848798#848798
– Frank Thomas – 2014-12-16T19:52:40.650So Notepad applies a read lock, and then releases it right after it has been loaded to primary memory? So this will allow for so called "interceding update"? While Word applies a write lock and releases it only after the file has been closed? @FrankThomas Thanks for the link! Is it true then that Word 2013 uses "transacted" temporary files? In other words, it actually works on the temporary file it makes, and when changes are saved it deletes the original file, and saves the current state of the document in a file with the same name as the original? – Samir – 2014-12-16T20:58:40.147
In simple terms, programs like Notepad and Paint don't care about who makes changes to the file and when? No concurrency and no synchronization control? – Samir – 2014-12-16T21:00:25.760
exactly. notepad and paint are not entirely safe for multi-user/multi-process access by processes that might write to them, because they preseent a race condition (who saves first?). Yes, Word and other office documents make temporary files (there are a few kinds, for a few purposes). I believe that the exact process involves preventing saving of changes if the source file has changed while the file was opened, but yes, it can come down to a race condition to see who saves first. The Office behaviour is complicated, so I recommend studying them in particular if you have need. – Frank Thomas – 2014-12-16T21:06:57.937
I thank you for the explanation! Now, would you please try to jot down a few sentences that summarize this? The previously provided answer was not entirely accurate. Try to contrast the behavior of Notepad to that of Word, in short, simple terms. I was mostly curious why Notepad allowed me to move the source file to recycle bin or even delete it, while it is open. I think I got the gist of it now. – Samir – 2014-12-16T21:15:52.000