Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated way to Delete Temp files 1

Status
Not open for further replies.

mofusjtf

IS-IT--Management
Apr 20, 2004
471
0
0
US
Is there an automated way to delete temp files from user profiles and the Windows temp location? Or is there some sort of tool that will do this?
 
You could do it with a batch file, that runs when a user logs on.

Easiest is to set your environment variables TEMP and TMP to something like c:\windows\Temp\

.... so then a batch file just needs to do a:

del /Q /S /F C:\windows\temp\*.*



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Is it safe to remove all *.tmp files?
Thread779-821227

Ramifications of deleting temp files at shutdown/startup?
thread779-949752

I am not a "Dossy" person but I do use something like this in a Batch file run at Startup or Logon, more experienced people will have better coding for you.


CD "C:\Documents and Settings\usernamexxxx1\Local Settings\Temp"
DEL *.tmp
DEL *.xml
DEL *.log
DEL *.txt
DEL *.mst
CD "C:\Documents and Settings\usernamexxxx2\Local Settings\Temp"
DEL *.tmp
DEL *.xml
DEL *.log
DEL *.txt
DEL *.mst
CD "C:\Documents and Settings\Administrator\Local Settings\Temp"
DEL *.tmp
CD C:\WINDOWS\Temp
DEL *.tmp
Exit
 
Check your %TEMP%. It isn't always in Documents and Settings. If you've gone the upgrade route from NT or 2000, it will be in WinNT\Profiles
 
>some sort of tool that will do this?

Windows Drive properties - General tab - Disk Cleanup button
 
Thanks everyone. I'll explore some of these options.
 
mofusjtf,

I think all the posts here are on target. I use dseaver's suggestion of CCleaner alot. You can also take a look at Steven Gould's Cleanup.

In tandem (Cleanup & CCleaner), with Microsoft Disk Cleanup you should get just about everything you want gone - unfortunately not automatically.

Please post back if you come up with an automated solution that seems to work good for you. I would be interested is seeing what you come up with.

Good Luck.

John

 
 http://stevengould.org/downloads/cleanup/CleanUp452.exe
Here's what I use at work/home:

1) Create "C:\Temp" folder.

2) Use "System Properties" to change "Environment Variables" for TEMP and TMP for both "User" and "System" to "C:\Temp".

3) Use a VBS "Shutdown" script (configured in "Group Policy Editor") to clear the contents of "C:\Temp" automatically.

The script is as follows. Just copy/paste it into Notepad and save it as something like 'cleantemp.vbs'. (It doesn't matter what you call it as long as the file extension ends with ".vbs".)

Code:
Const oSrc = "C:\Temp"
Dim WSH, FSO
Set WSH = WScript.CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
FSO.DeleteFolder oSrc,True
FSO.CreateFolder oSrc
WScript.Quit()

Note 1: I had to change this to a "Startup" script on PC's running Adobe Photoshop CS3. I think (but I'm not yet sure) it's because Photoshop is very slow to release file locks on its temporary files.

Note 2: I've noticed that sometimes there's an error running the script on shutdown following installation of MS Critical Updates so I guess that MS is temporarily preventing the TEMP/TMP variable location area from being emptied until next bootup. However, I can still continue to shutdown and the PC's are fine again after a subsequent re-boot.

Hope this helps...
 
Rick:

Gee, that sounds suspiciouslly like what I suggested. ;-)



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Greg,

You're right! I wasn't trying to detract from your suggestion and hope that's not how it sounds. I was just trying to show it could be done just as easily with a VBS script as with a batch file.

In my defence <grin>, my reply was slightly different. We have a 3rd-party app used at work which leaves confidential info in temp files so needed a method of clearing the files at shutdown, not logon (in case of overnight theft of a PC). I decided to delete the folder then recreate it instead of deleting the contents instead.

Rick
 
The only problem with using a batch file to do:
Code:
del /Q /S /F C:\windows\temp\*.*
is that if one of the files is in use, DEL will stop without deleting the rest of the files which aren't in use. I can't believe they haven't added a switch yet to skip files that can't be deleted and keep going...
I wrote my own DEL.exe program that deletes everything it can and just prints out the ones it couldn't delete.
 
cpjust,

As you may have seen, I've had a problem with Adobe Photoshop CS3 not un-locking temporary files in use. I resolved this with a kludge... which I'm not happy about.

As a great believer in not re-inventing the wheel (OK, so I'm just lazy <grin>), are you willing/able to share your DEL.exe program?

 
I wrote it a couple years ago, and I think I was going to add more functionality to it, but I never got around to it. Currently you just specify a temp directory and it will delete *.* in that directory & all sub-directories. So it's REALLY easy to screw yourself big time if you make a mistake! Type very carefully.
That being said, I offer no warranty and assume no responsibility for the use (or misuse) of the program.

Do you know any free hosting sites that allow ZIP files? If you can find one, I'll put it on there.
 
Have a look at it is what the "Step3 Attachment" below the Reply Box refers to. I don't think there are any restrictions on file types as long as you don't exceed 1GB in total.
 
If you have a hotmail account, you will find that Microsoft added several things that you can access and set up when they transitioned to "Live". One of them is an option called Skydrive, which allows you to store files and link to them publicly. While I haven't tried linking images through it, I've stored a few files and linked to them in forums and it works very well.

I'm not sure if there's a specific file upload limit, but the total capacity limit is 1GB.

Hope that helps.
 
Wow, I must say. This thread has created quite an interesting and informative conversation. Thank you all for your valuable posts.
 
Just to add to the ever growing list. I use VBScript to automate the XP and Windows 2003 Disk Cleanup Wizard.

Details at
You could also use a simpler vbscript like my CleanBadMail.vbs found in my FAQ faq955-6503.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
You can also use cleanmgr in a batch file .... run it with sageset:1 first and choose the options you want to clean (temp, recycle, offline, setup etc and if you want to compress) and then create a batch file to run cleanmgr with sagerun:1 option.

<Do I need A Signature or will an X do?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top