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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone remember DOS? 1

Status
Not open for further replies.

OfficeAnimal

Technical User
Jun 4, 2009
277
AU
Arrrggghhh!!! [curse] I know!!! [hairpull]

However, I find myself having to write a batch file for the first time since Luis Suarez got his first tooth.

I want it to, amongst other things, eliminate folders with names like
_AI62E.tmp, {5dd6319d-705c-4ac4-ba7a-b8b1c832dc0a} and ~DF2EEF8AFB40B642B6.tmp
from \appdata\local\temp in Windows 7.

A simple RD (RMDIR) command like
rd /q /s ~*.tmp
gets rejected for a syntax error. Can some kind soul please set me straight?

Thanks

"Truth will sooner come out from error than from confusion."
Francis Bacon (1561-1626)
 
Sadly RMDIR does cannot use wildcards. You have to write a loop:

[tt]for /D %f in (~*.tmp) do rmdir %f /s[/tt]

(the above is for use directly on the command line; double up the % when using in a batch file)

Alternatively, You might like to start looking at the somewhat more powerful and flexible (and modern) Powershell ...
 
Rather than a batch file to delete things based on names, why not run (or schedule) Windows' own cleanup tool? See this page for details on its parameters:
How to Automate the Disk Cleanup Tool in Windows XP and Windows 7

Basically you create a saved setting (a set of cleanup tool options, such as just deleting temp files) with [tt]cleanmgr /sageset:n[/tt] (where n is a number you choose, so you can have many different saved settings) and run it using [tt]cleanmgr /sagerun:n[/tt].

If you do it the way you're trying you could end up deleting files/folders that are still needed. If you decide to go ahead anyway, you can replace [tt]\appdata\local\temp[/tt] with [tt]%TEMP%[/tt].

Nelviticus
 
Not much to add to the above answers, just want to offer salute for the World Cup reference. Fantastic.

[2thumbsup]

You got a genuine laugh out of me.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks strongm

I wound up using

REM Delete folders with names in Braces
pause
for /D %%f in ({*}) do rmdir %%f /s /q
dir

REM Delete folders with names starting with Underscore
pause
for /D %%f in (_*.tmp) do rmdir %%f /s /q
dir

REM Delete folders with names starting with Tilde
pause
for /D %%f in (~*.tmp) do rmdir %%f /s /q
dir

Only the folders starting with Tilde were not deleted. There is no notification that they are protected.

I inserted the /q because otherwise I would be there for a month [bugeyed]

"Truth will sooner come out from error than from confusion."
Francis Bacon (1561-1626)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top