Home / Microsoft / Microsoft DOS / Remove the content of Temp Directory!???
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2  All - (Bottom) Print
Author Topic: Remove the content of Temp Directory!???  (Read 619 times)
Floppyman
Topic Starter
Rookie



Thanked: 2
Posts: 30


« on: November 15, 2011, 07:11:54 AM »

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:
IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #1 on: November 15, 2011, 10:11:58 AM »

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.  ;D
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,876

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #2 on: November 15, 2011, 10:37:33 AM »

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%\*.*"

IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
Linux711
Adviser



Thanked: 49
Posts: 921

Certifications: List
Computer: Specs
Experience: Experienced
OS: Windows XP

Programming Blog 1
« Reply #3 on: November 15, 2011, 10:49:03 AM »

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.
IP logged

YouTube

"Genius is persistence, not brain power." - Me

"Insomnia is just a byproduct of, "It can't be done"" - LaVolpe

BC_Programmer
Mastermind


Thanked: 697
Posts: 15,876

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #4 on: November 15, 2011, 10:55:18 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.
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
Linux711
Adviser



Thanked: 49
Posts: 921

Certifications: List
Computer: Specs
Experience: Experienced
OS: Windows XP

Programming Blog 1
« Reply #5 on: November 15, 2011, 11:03:16 AM »

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
IP logged

YouTube

"Genius is persistence, not brain power." - Me

"Insomnia is just a byproduct of, "It can't be done"" - LaVolpe

Floppyman
Topic Starter
Rookie



Thanked: 2
Posts: 30


« Reply #6 on: November 16, 2011, 02:30:57 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.
IP logged
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,876

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #7 on: November 16, 2011, 03:51:19 AM »

is the 4KB used for the folder's directory entry really that critical?
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #8 on: November 16, 2011, 09:27:19 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.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
Floppyman
Topic Starter
Rookie



Thanked: 2
Posts: 30


« Reply #9 on: November 25, 2011, 10:07:04 PM »

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.
IP logged
Salmon Trout
Sage



Thanked: 546
Posts: 7,948

Computer: Specs
Experience: Beginner
OS: Unknown

1
« Reply #10 on: November 26, 2011, 12:35:45 AM »

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.
« Last Edit: November 26, 2011, 12:58:40 AM by Salmon Trout » IP logged


Proud to be European
Salmon Trout
Sage



Thanked: 546
Posts: 7,948

Computer: Specs
Experience: Beginner
OS: Unknown

1
« Reply #11 on: November 26, 2011, 12:49:54 AM »

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.

IP logged


Proud to be European
kimsland
Intermediate



Thanked: 10
Posts: 127

Experience: Guru
OS: Windows XP
Leaving, CH can obviously do without my support.

« Reply #12 on: November 27, 2011, 07:59:38 AM »

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
IP logged
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,876

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #13 on: November 27, 2011, 10:31:26 AM »

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.
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
patio
Moderator
Genius



Thanked: 1069
Posts: 11,351

Experience: Beginner
OS: Windows 7


Maud' Dib

« Reply #14 on: November 27, 2011, 11:18:19 AM »

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.
IP logged

   
"
All generalizations are false, including this one.  "
Pages: [1] 2  All - (Top) Print 
Home / Microsoft / Microsoft DOS / Remove the content of Temp Directory!??? « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.117 seconds with 20 queries.