Deleting Temporary Files
Can I safely delete temporary (.TMP) files?
Temporary files are just that, designed to be temporary. But, that does not always mean you can safely delete them. A running program, for example, may have created a temporary file that, if deleted, could cause problems for that program. Windows is an example of this; it creates temporary files that are used during any given session. While it usually recovers and recreates files it finds deleted, that is not always the case.
Consider the following as guidelines but not guarantees (make certain the file is actually a temporary file and not some critical data file with a .TMP extension):
- If the .TMP file date is earlier than the last time the computer was started and the file size is zero bytes it's almost always safe to delete the file.
- If the .TMP file date is earlier than the last time the comptuer was started it's usually safe to delete the file.
- Everything else depends on the situation.
Also, note that not all temporary files have the file extension .TMP.
Many times programs will use a tilde (~) as part of a file's name to indicate a temporary file; however, these are much more often files in use. For example, a word processor might use .WP for it's files and when it opens a file it will rename the opened version to .WP~ or .~WP and then save a copy to the real file name ending in .WP. On the next save, the .WP~ or .~WP file may be renamed to .BAK and the newer file given the tilde. And so on, through the entire editing session. If power goes out or some other event interrupts the process then a file with a tilde might be left on the system -- but this is a good thing as it will likely be a newer version of what you were working on than the .BAK file left from the last save. So, despite the fact that it's a temporary file you probably would not want to delete the file until you are certain you have recovered all useful information from the file. Some programs will even do this automatically for you if you restart them after a failed session.
Some people like to create batch (.BAT) files to automatically clean out their system on each system start.
This can be a useful process if you've identified temporary files that tend to accumulate over time. But, if you do this be certain you learn and understand the batch file commands as well as the effects of any wildcards you might use.
To cite a bad example, I saw one batch file that had a command like DEL /f /s /q *.*TMP in it.
If the person had run that batch file from the root directory of their hard disk EVERY file on their hard disk would have been deleted with no permission needed! The problem is in the placement of the second asterisk.
What they wanted to do was delete every file with any variation on .TMP as a file extension (not a particularly good plan but...). The problem is that when the system came to the second wildcard asterisk it saw it as "everything" and paid no attention to the TMP characters after it. So basically this was a DEL *.* command and the /q attribute said to do it quietly and the /s attribute said to go through all subdirectories automatically.
If you want to create a batch file with a DEL or ERASE command in it fine, but test that file first. Replace all the DEL or ERASE commands with DIR commands and then run the file. You will then see the name of everything that will be deleted and can decide if that's what you really want to do and avoid problems like the above.