pscowboy

Distinguished
Apr 24, 2002
1,129
0
19,290
For all you old "Dosasauruses" out there, here's a challenging batch file I'd like to get off the ground.

I would like to delete files in my two default Temp locations always from yesterday on back.

Is there a way to invoke "Dir" (inside the batch file) to separate the files as to date and send them to a staging folder where I can use "Del" to remove them?
There are always fresh temp files generated each bootup to prevent a del *.* scenario from working.

I've only been using XP for a couple of weeks and I found over a thousand garbage temps in both locations. I'd like to work toward the end of keeping that to a minimum; ergo the batch file idea.

What say you guys?
 

riser

Illustrious
Why do you only want to keep the last two days? You're better off just deleting it all.

You also might want to consider running the Prefetch and deleting that information every so often.. - start - run - "prefetch"
 

fishmahn

Distinguished
Jul 6, 2004
3,197
0
20,780
pseudodosbatfilecode:

for %%i in (dir c:\yourtempfoldernamehere /B /OD) DO del %%i

This will delete each file in the folder starting with the oldest. Since only the newest files generate an error because they're in use, it should solve your issue of avoiding del *.*. If I'm wrong in the assumption that you just can't do a del *.* because of in use errors, and there's another reason you need to keep the current day's files, then the above won't work.

I haven't done any extensive 'batch programming' in a few years so my syntax may be off for the 'for' command, but that's how it was done previously.

Mike.

<font color=blue>Outside of a dog, a book is man's best friend. Inside the dog its too dark to read.
-- Groucho Marx</font color=blue>
 

pscowboy

Distinguished
Apr 24, 2002
1,129
0
19,290
You get "in use" errors on the fresh stuff and the deletions are halted; thus the batch file will fail.

As to Fishmahn's idea, I"ll noodle around with that.
 

TRENDING THREADS