muchlux Posted July 13, 2006 Share Posted July 13, 2006 Hi,I want to clean the user %temp% folder and some others automatically after logon.I have tried to use the del command, but it seems that XP always stores some temp files which cannot be deleted. So the del stops execution when reaching a file which cannot be accessed.Is there an alternative method to delete files, skipping not accessable files?(Like the robocopy for copying?)I do not want to use any third party tools. Link to comment Share on other sites More sharing options...
Delprat Posted July 13, 2006 Share Posted July 13, 2006 maybe the /Q switch :DEL /F/S/Q %TEMP%\*.*If i were you, i would use the clean manager. run CLEANMGR /SAGESET:99 ; check what you want to delete, then run CLEANMGR /SAGERUN:99 each time you want to cleanup things. (you can have multiple schemes, just change the number)++ Link to comment Share on other sites More sharing options...
muchlux Posted July 14, 2006 Author Share Posted July 14, 2006 I found a weird solution: md %temp%\xvdghhfzstart /wait robocopy.exe %temp% %temp%\xvdghhfz /S /E /MOVErd /S /Q %temp%\xvdghhfzbut it works.Of course it cannot delete the temp files inuse but all others Link to comment Share on other sites More sharing options...
Esquire Posted July 17, 2006 Share Posted July 17, 2006 You can also use a tool: Empty Temp FoldersIt's written for Windows 2000, but I have been using it on Windows XP since the beginning without problems. Link to comment Share on other sites More sharing options...
idesksoft Posted July 18, 2006 Share Posted July 18, 2006 Good program! Link to comment Share on other sites More sharing options...
Andromeda43 Posted July 23, 2006 Share Posted July 23, 2006 Back in the early days of Windows 98, I wrote a cleanup batch file which I called Hoover.bat.I named it after the Vacc. Cleaner. I sent it via file transfer in Paltalk and via EMails to hundreds of users worldwide. It's still available for quick download on My Webpage (It's for 98, 98/SE and ME only)It uses 'Deltree.exe' a fabulous windows routine that was left out of Windows XP.Once added to XP, it runs just fine, as it did in 98.I've put the new XP-Cleanup program, XPCleanup.bat on my website also, and I've included the 'Deltree.exe' program file as well.Both XPCleanup and Deltree.exe are included now in my "Care Package" that I've placed for download on a rented Server at My Download Site.There's even a little batch file there to install it for you. If you want to really do a 'tune-up' on XP, download the Care Package, but read the instructions file before running any of the programs in the zipped file.XPCleanup.bat, will clean out all the junk that windows likes to keep on your HD.Putting a shortcut to it in your "Startup" folder will give you a daily cleanup, sort of like FREE Maid Service everytime you boot up your PC.I run this myself and install it for all my customers. They love it, getting rid of junk everytime they boot up.It only takes a second or two to run and then it's done. It doesn't stay in memory.Well, that's MY answer to the Junk problem. Cheers!Andromeda43 B) Link to comment Share on other sites More sharing options...
T D Posted July 25, 2006 Share Posted July 25, 2006 (edited) CMDOW @ /HIDREG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v "Empty Temp Folders" /d ".\deltemp.cmd" /fattrib -r -a -s -h /S /D "%TEMP%"cd %temp%del /F /S /Q *.*rd /s /q "%temp%\"attrib -r -a -s -h /S /D "%SYSTEMROOT%\Temp"cd %systemroot%\tempdel /f /s /q *.*rd /s /q "%SystemRoot%\Temp\"attrib -r -a -s -h /S /D "%TEMP%\Temporary Internet Files"cd %temp%\Temporary Internet Filesdel /f /s /q *.*rd /s /f /q "%temp%\Temporary Internet Files\"cd\del *.tmp /s /f /qdel index.dat /s /f /qPut all of this in a batch file into any directory, yes any and it will work. Will also work unattendedly. It will add a startup entry to the current batch file, but it has to be called deltemp.cmd. Or you can change the deltemp.cmd to something else in the REG ADD entry and rename the file accordingly.@andromeda You can use something similar to deltree.exe with "rd.exe" and the switch /Q /S But deltree is easier for typing purposes Edited July 27, 2006 by T D Link to comment Share on other sites More sharing options...
Rudi1 Posted July 25, 2006 Share Posted July 25, 2006 CMDOW @ /HIDREG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v "Empty Temp Folders" /d ".\deltemp.cmd" /fcd %temp%del /F /S /Q *.*cd %systemroot%\tempdel /f /s /q *.*cd\del *.tmp /sPut all of this in a batch file into any directory, yes any and it will work. Will also work unattendedly. It will add a startup entry to the current batch file, but it has to be called deltemp.cmd. Or you can change the deltemp.cmd to something else in the REG ADD entry and rename the file accordingly.@andromeda You can use something similar to deltree.exe with "rd.exe" and the switch /Q /S But deltree is easier for typing purposes This cmd file work like a sharm! Really thank you for it! Link to comment Share on other sites More sharing options...
mazin Posted July 25, 2006 Share Posted July 25, 2006 CMDOW @ /HIDREG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v "Empty Temp Folders" /d ".\deltemp.cmd" /fcd %temp%del /F /S /Q *.*cd %systemroot%\tempdel /f /s /q *.*cd\del *.tmp /sIt's not a good idea to use HKLM if the computer is a multi-user environment. B) You'd better use HKCU, instead; so that every user can be able to control their %TEMP%. However, DEL command does not delete directories, but files only. So, what about directories inside %TEMP%? Link to comment Share on other sites More sharing options...
T D Posted July 26, 2006 Share Posted July 26, 2006 I just put HKLM because well, it's temp files!And dirs inside temp, because of the /s switch, the files inside them get deleted but the folders themselves don't. It's not too much of a problem that even though after about a year, %temp% will slow ur pc down a bit because of a lot of folders. But once a yr, surely u can find time to delete files in %temp% I tried deleting dirs with rd but it doesn't work with wildcards Here's an idea for emptying IE cache and cookies. Edited post above. Link to comment Share on other sites More sharing options...
mazin Posted July 27, 2006 Share Posted July 27, 2006 I tried deleting dirs with rd but it doesn't work with wildcards Yes, that's what MS says. This is what I say:RD command is ABLE to delete a bunch of directories even without wildcards .rd /S /Q "%TEMP%\"Also, the back slash ensures that the TEMP folder itself is not removed.It's not documented, but just a brain HARSH! Then, the whole %TEMP% clean-up is solved, this way:attrib -r -a -s -h /S /D "%TEMP%"del /F /S /Q "%TEMP%\*.*"rd /S /Q "%TEMP%\"Hope you like it. B) Link to comment Share on other sites More sharing options...
Rudi1 Posted July 27, 2006 Share Posted July 27, 2006 Hi mazin!Can you post complete cmd file?thx! Link to comment Share on other sites More sharing options...
T D Posted July 27, 2006 Share Posted July 27, 2006 Thnx mazin, why M$ didn't document this... updated cmd file above. Link to comment Share on other sites More sharing options...
mazin Posted July 28, 2006 Share Posted July 28, 2006 Hi mazin!Can you post complete cmd file?thx!T D has got a nice one there.However, there are different scenarios. I don't know yours, specifically!I'm going to list what in mind for cleaning up a user's TEMP directory, leaving %SystemRoot%\Temp as it is.I'll assume that your PC has a single user or multiple users with the same preference of cleaning up their TEMP directory.Scenario 1: CleanUp on demand.Inside any batch file you use during Windows Setup, add the following lines:echo @ECHO OFF>%SystemRoot%\CL.CMDecho echo.>>%SystemRoot%\CL.CMDecho echo.>>%SystemRoot%\CL.CMDecho echo Cleaning Up My %TEMP%>>%SystemRoot%\CL.CMDecho attrib -r -a -s -h /S /D "%%TEMP%%">>%SystemRoot%\CL.CMDecho del /F /S /Q "%%TEMP%%\*.*">>%SystemRoot%\CL.CMDecho rd /S /Q "%%TEMP%%\">>%SystemRoot%\CL.CMDThat script can be put in a batch file running at T-39, T-13, T-12, T-9, and actually at any stage.The script creates CL.CMD in Windows folder. And, when run, CL.CMD cleans the user's TEMP directory.Being in Windows folder, CL.CMD can be called anytime by any user to do its job.A user can just go to Start-->Run and type CL, then press ENTER. And VOILA!Scenario 2: CleanUp on demand and at System StartUp.We use the same script above with extra one line (REG ADD HK..):REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v "TEMP CleanUp" /d %SystemRoot%\CL.CMDecho @ECHO OFF>%SystemRoot%\CL.CMDecho echo.>>%SystemRoot%\CL.CMDecho echo.>>%SystemRoot%\CL.CMDecho echo Cleaning Up My %TEMP%>>%SystemRoot%\CL.CMDecho attrib -r -a -s -h /S /D "%%TEMP%%">>%SystemRoot%\CL.CMDecho del /F /S /Q "%%TEMP%%\*.*">>%SystemRoot%\CL.CMDecho rd /S /Q "%%TEMP%%\">>%SystemRoot%\CL.CMDSame as above, the script creates CL.CMD in Windows folder. Additionally, it puts a call for it in HKLM\Run making it be run at every system startup, whatever the user account being logged in.Same as above, CL.CMD cleans the user's TEMP directory.Being in Windows folder, CL.CMD can be called anytime by any user to do its job, and not only at system startup.A user can just go to Start-->Run and type CL; then press ENTER to run CL.CMD!One thing I'm not sure of is wether REG ADD works at T-39! Surely, REG ADD works at the other stages.Note:In the second scenario, if the PC is a multi-user machine where each user wants to control his own TEMP, then we just replace HKLM with HKCU.This requires a user to log in using his own account, then apply the script.In such a case, we add that script to a batch file running at T-13. I haven't tested it at T-12, however.The script, in that case, will be slightly different as follows:echo @ECHO OFF>"%UserProfile%\Desktop\DELifNO.CMD"echo REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v "TEMP CleanUp" /d %%SystemRoot%%\CL.CMD>>"%UserProfile%\Desktop\DELifNO.CMD"echo del %%0>>"%UserProfile%\Desktop\DELifNO.CMD"echo @ECHO OFF>%SystemRoot%\CL.CMDecho echo.>>%SystemRoot%\CL.CMDecho echo.>>%SystemRoot%\CL.CMDecho echo Cleaning Up My %TEMP%>>%SystemRoot%\CL.CMDecho attrib -r -a -s -h /S /D "%%TEMP%%">>%SystemRoot%\CL.CMDecho del /F /S /Q "%%TEMP%%\*.*">>%SystemRoot%\CL.CMDecho rd /S /Q "%%TEMP%%\">>%SystemRoot%\CL.CMDSo, when a user logs in using their account, they will find "DELifNO.CMD" on their desktop.If a user wants a cleanup on demand, they just delete the file "DELifNO.CMD"! Otherwise, ie both cleanups, they run "DELifNO.CMD".Ah, and "DELifNO.CMD" is self-deleted.I hope I was clear and well understood. Link to comment Share on other sites More sharing options...
Rudi1 Posted July 28, 2006 Share Posted July 28, 2006 Your explanation is more then good I will try it when I install windows again,but i'am shure that work just fine.I'am always like to have util like this,becouse some of files is really hard to delete from temp folders! Thanx TD who is post this script and you for finnished it!!take care guys! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now