1.

Solve : Remove the content of Temp Directory!????

Answer»

Hello folks, i want a bat file to remove every thing from the %temp% directory and my code is Code: [Select]del /q "%userprofile%\Local Settings\Temp\*.* but this bat file only removes the files and not the folders as ccleaner does.
So i am asking if anyone knows of a better bat files that could remove the folder as well.

Thank you, hoping for a suitable solution:Try using this:

Code: [Select]rd /s /q "%userprofile%\Local Settings\Temp"

You may need to add this to ensure you don't have system issues.

Code: [Select]md "%userprofile%\Local Settings\Temp"

BTW, this isn't working on my system because there are processes still running that are connected to files within the Temp directory. You may need to taskkill some stuff before the whole thing will work.

Personally, I think they should just bring back deltree and we'll call it a day.  Code: [Select]del /q /s "%userprofile%\Local Settings\Temp\*.*

There is no reason to delete the temp folder itself. And using that path specification is specific to Windows XP... why not use:

Code: [Select]del /q /s "%temp%\*.*"

This is more of a suggestion than an answer to your question, but anyway. It's so much nicer to just make a RAM disk and then re-route all your temp files to the RAM disk so whenever you reboot, then temp is automatically lost because the RAM is cleared. If you're going to delete the temp anyway, then why even store it on the hdd? It's just going to get fragged faster and bloated with crap. I think this should be built into future versions of Windows. BC: I know you're going to say why I am wrong. Go ahead.

Anyway, if you're interested, I can provide you with more instructions on how to do this. Quote from: Linux711 on November 15, 2011, 10:49:03 AM

BC: I know you're going to say why I am wrong. Go ahead.

Main problem would be rerouting the temp files to the RAM disk, since %TEMP% is a per-user variable. And of course the issue of using up your RAM for the otherwise menial task of storing temporary files. Aside from that, it's not a terrible idea on XP and earlier if the system has GOBS of RAM but low disk space. Quote
Main problem would be rerouting the temp files to the RAM disk, since %TEMP% is a per-user variable.

True. That's why I have created a batch that sets temp variables easily, so that it can be done for each user.

Code: [Select]echo off
SET /P DIRNAME=Type the path to the RAMDrive:
REG ADD "HKCU\Environment" /v TEMP /t REG_EXPAND_SZ /d %DIRNAME% /f
REG ADD "HKCU\Environment" /v TMP /t REG_EXPAND_SZ /d %DIRNAME% /f
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TEMP /t REG_EXPAND_SZ /d %DIRNAME% /f
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TMP /t REG_EXPAND_SZ /d %DIRNAME% /f
Quote from: Raven19528 on November 15, 2011, 10:11:58 AM
Try using this:

Code: [Select]rd /s /q "%userprofile%\Local Settings\Temp"
BTW, this isn't working on my system because there are processes still running that are connected to files within the Temp directory. You may need to taskkill some stuff before the whole thing will work.

aannnnn Raven19528 what do you know Code: [Select]rd /s /q "%userprofile%\Local Settings\Temp"
your code works and it removes the folder as well as the files. Good going, by the way rd is the remove directory isn't it:then how come it removes the file as well . Sorry BC Programmer your code i.e., Code: [Select]del /q /s "%userprofile%\Local Settings\Temp\*.*  doesn't work it only removes the files same like my code except giving the /s switch. Same was for the other codes.

Anyways isn't it GREAT to know what a bat file can achieve to do the same task.

PS: Just thanked Raven for this job.is the 4KB used for the folder's directory entry really that critical? Quote from: Floppyman on November 16, 2011, 02:30:57 AM
by the way rd is the remove directory isn't it:then how come it removes the file as well .

Using the /s switch on the rd (which yes, is remove directory, same as rmdir) causes it to remove the folder and all files and folders within the directory. You can view the full explanation by typing rd /? at the cmd prompt.Hello hello newsflash Code: [Select] rd /s /q "%userprofile%\Local Settings\Temp" this code of Raven has stopped working , last time i had to perform a System Recovery and what do you know the bat file doesn't work to well.
 It removes the TEMP folder entirely, has  anyone even been trying this out. Its really important for me.

BC programmers does perform a little better Code: [Select]del /q /s "%userprofile%\Local Settings\Temp\*.*
Any suggestion i have to be better aware next time when i thank someone.
Little HELP here. Quote from: Floppyman on November 25, 2011, 10:07:04 PM
Any suggestion i have to be better aware next time when i thank someone.
Little help here.

What I do is perform rd /s . (can you see the dot?) from within each directory I want to clear. Being logged in to a directory via the CD command means it won't get deleted. I tend to always add the /d switch to the cd command but I guess that's a personal preference.

To turn off the "., Are you sure (Y/N)?" prompt, use the /q switch and if you don't want to see the messages about what it couldn't delete, add 2>nul to redirect stderr to the null device.

For example: (the paths are mine, yours may differ)

cd /d %temp% & rd /s . /q 2>nul
cd /d %windir%\temp & rd /s . /q 2>nul


And Floppyman, maybe a bit less of the smart mouth? People have given their time freely to help you, and have done their best. Crude ungrateful sarcasm spoils the forum and looks bad. Anyhow, that's just my opinion.
Quote from: Floppyman on November 25, 2011, 10:07:04 PM
Little help here.

No need for this either. Helping you is not obligatory, and the goodwill that motivates people to do so is a fragile thing that is easily dispersed, as I hinted above.

I use to have this on a CD
Of course my 'CleanIt' folder also contained these files:
AllDone.exe (this is a 'dropcount' file)
CHOICE.com
sizeOLD.exe (this is a 'dropcount' file)
sizeNEW.exe (this is a 'dropcount' file)
taskkill.exe
TempClose.exe (An old AutoIt file)
wscript.exe

Anyway, if you want me to zip it up and attach all this stuff let me know
Actually not even sure if I'm allowed to do that?

It was originally made by me for Windows XP terminals that needed their Temp folders cleaned out periodically.
I also put an invisible script on it http://forums.techguy.org/dos-other/644932-solved-howto-run-batch-file.html

But these days, CCleaner has command prompt options, so its of no use anymore

Quote
echo off
TITLE ^>^>Temp Cleaner^<^<
start %cdrom%\CleanIt\sizeold %temp%
start /D%temp% /max .
rem start /D%temp% .
call %cdrom%\CleanIt\CHOICE /T:N,3
call %cdrom%\CleanIt\taskkill /im sizeold.exe
attrib -r -s %temp%\*.* /s
del %temp% /f /s /q
rmdir %temp% /s /q
del "%userprofile%\Recent" /q
start %cdrom%\CleanIt\sizenew %temp%
call %cdrom%\CleanIt\CHOICE /T:N,3
call %cdrom%\CleanIt\taskkill /im sizenew.exe
call %cdrom%\CleanIt\CHOICE /T:N,1
start %cdrom%\CleanIt\tempclose.exe
start %cdrom%\CleanIt\AllDone %temp%
call %cdrom%\CleanIt\CHOICE /T:N,3
call %cdrom%\CleanIt\taskkill /im AllDone.exe
exit
If there is ONE thing I've yet to understand, it's people's obsession with files in the temp directory, and treating their deletion like some kind of ritual involving relatively complex scripts. Could not agree more...course there are 100's of other relatively simple tasks we see people attempting to write complex scripts for as well.


Discussion

No Comment Found