Deleting temporary files automatically



Q Thanks for teaching me heaps over the past few years. When people ask me how I know so much, I tell them that it's thanks to columns like yours. But for every one thing I learn there are at least two that I don't, and one of these relates to a problem with temp files. I would like to be able to set up a line in my autoexec.bat that automatically deletes these files on startup, using DOS. Is the following line correct, and why doesn't it work with Windows 95?
SET TEMP=C:\TEMP IF EXIST *.TMP, DEL*.TMP
- Kristina Williams

A Many applications store data in temporary files. If these programs always exited cleanly, and if Windows 95 never crashed, such files would always be deleted when you shut down your system. But while we wait for utopia, we need to take steps to ensure that temporary files don't end up as permanent debris.
As Kristina says, it's a good idea to place a statement in the autoexec.bat file which will automatically remove defunct temporary files at startup. You can do this with a text editor, such as Notepad. However, Kristina's example places two statements on a single line, and the syntax isn't quite right.
The command SET TEMP=C:\TEMP tells the operating system to use the TEMP folder on Drive C: to store temporary files. If the SET TEMP statement is omitted, Windows 95 will use the default temporary files directory, normally C:\WINDOWS\TEMP. In fact, you can use any folder you like to store temporary files -- just be sure that it exists!
There are various ways to write a statement to remove files from the temporary directory, but the following example works as well as any. On a new line in the autoexec.bat file, type:
ECHO Y | DEL C:\TEMP\*.*
The "ECHO Y |" portion of the statement is important because it answers the DEL command's "Are you sure?" prompt automatically, without the need for user intervention.
A word of caution: when adding statements like this to your autoexec.bat file, always include the full path to the temp folder, ie DEL C:\TEMP\*.* and NOT DEL *.*. The latter command will delete all files in the current directory. And if the current directory happens to be C:\WINDOWS or C:\DATA, you will delete more than you bargained for!
- Neville Clarkson


Category: Win95
Issue: Feb 1998
Pages: 156

These Web pages are produced by Australian PC World © 1997 IDG Communications