delete files older than X date


S

Scott Closter

Is there a command line utility (delete does not seem to
have this function) where you can specify to delete files
older than a specied number of days?
 
Ad

Advertisements

P

Paul R. Sadowski

Scott Closter said:
Is there a command line utility (delete does not seem to
have this function) where you can specify to delete files
older than a specied number of days?
You could do it with robocopy if you have it from the resource kit.
SOmething like this:

md %temp%\12345del
robocopy d:\stuff %temp%\12345del /s /mov /minage:10
rd /q /s %temp%\12345del

minage represents the minimum age in days to delete. 10 days or older in the
example above.

/s means move the files from subdirs as well.

/mov moves and deletes the source files. /move moves and deletes both files
and directories.

In summary, you are moving files x days and older to a temp dir. then
deleting the temp dir.

robocopy source destination /s /mov /minage:x

There are probably dedicated progs and batch solutions to do this but this
is nice and simple. robocopy is free in the 2003 server resource lit
(downloadable) and people say it works on 2K as well.
 
P

Phil Robyn

Scott said:
Is there a command line utility (delete does not seem to
have this function) where you can specify to delete files
older than a specied number of days?
Download the free program FORFILES.EXE from ftp://ftp.microsoft.com/ResKit/y2kfix/x86/
 
S

Scott Closter

Hi Paul, that would work indeed. I have been using
robocopy for other purposes, so I think that would easily
work for what I need. Thanks.
 
Ad

Advertisements

O

Olaf Engelke [MVP]

Phil said:
Download the free program FORFILES.EXE from
ftp://ftp.microsoft.com/ResKit/y2kfix/x86/
The syntax for deleting the files would be:

forfiles.exe -p C:\Test -m *.* -d-X -c "cmd /c del @FILE"

Instead of X use your X+1 as value.
If you need to include hidden files, add /a, for files in subfolders /s to
the DEL command.
(Tested on Windows Server 2003).

Best greetings from Germany
Olaf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top