Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

find and delete files older than x days

6 views
Skip to first unread message

Gary Chan

unread,
Jan 3, 2003, 6:15:37 PM1/3/03
to
Seems simple task to do in batch file but I have no idea
what commands to use. Can anyone provides some ideas or
sample? I've found some third parties utilities but they
all do lot more than what I needed and usually involved
installing bunch of program files and dll's. I need to
automate such cleanup on a very critical w2k server and
trying to keep this as simple as possible.

Phil Robyn

unread,
Jan 3, 2003, 7:16:52 PM1/3/03
to

Use FORFILES.EXE from the Resource Kit. If you don't have
the Resource Kit, you can download FORFILES.EXE from

ftp://ftp.microsoft.com/reskit/y2kfix/x86/


--
U s e ' R e p l y - T o ' a d d r e s s o r
u n z i p ' F r o m ' t o s e n d m a i l

Jonathan de Boyne Pollard

unread,
Jan 18, 2003, 7:30:11 AM1/18/03
to
GC> Seems simple task to do in batch file but I have no idea
GC> what commands to use.

<URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/common-tasks-with-jpsoft-clis.html#ProcessByDate>

Patrick Peccatte

unread,
Jan 19, 2003, 9:37:37 AM1/19/03
to
Delenda Cleanup Software lets you parameter files to delete using age in hours, days etc and will do it automatically for you
also in command line mode or called from a batch file:
http://peccatte.karefil.com/software/Purge/DelendaEng.htm

"Jonathan de Boyne Pollard" <J.deBoyn...@tesco.net> a écrit dans le message de news: 3E2948D3...@tesco.net...

Victor

unread,
Jan 20, 2003, 5:55:24 AM1/20/03
to
This bit of batch sorts all the .log files by date in newest to oldest order
into a text file then runs through the text file one line at a time skipping
the first 6 .log files (newest by date) then deles the rest. replace del
with echo to test prior to actually running.

dir D:\*.log /o-d /b > D:\log_file_list.txt
FOR /F "tokens=1 skip=6" %%i in (D:\log_file_list.txt) do del D:\%%i
del D:\log_file_list.txt


"Jonathan de Boyne Pollard" <J.deBoyn...@tesco.net> wrote in message
news:3E2948D3...@tesco.net...

Kan Yabumoto

unread,
Jan 20, 2003, 9:24:47 PM1/20/03
to
Since the built-in DEL (or ERASE) command does not allows you
to specify the age of the file, you need to find something else.
Since there is no direct support by the batch file itself
you need to find some tool which provides such a function.

XXCOPY is one solution which provide a one-line command which
is more than capable of finding and deleting files by age.

XXCOPY is an enhanced XCOPY with rich set of command witches.
It is available as freeware for personal use at

http://www.xxcopy.com

Here are some basic command switches

/L // list-only (no copy or delete)
/RS // remove (delete) from the source
/DB#<n> // select files that are n days or older
/DA#<n> // select files that are n days or younger

Here's a few examples:

xxcopy c:\mydir\* /L /DB#10 // list files 10 days or older
xxcopy c:\mydir\*.DOC /L /DB#7 // list *.DOC files, >= 10 days old
xxcopy c:\mydir\* /RS /DB10 // delete files 10 days or older
xxcopy c:\mydir\* /RS /DB#10 /DA#30 // files 10-30 day sold
xxcopy c:\mydir\* /RS /DB#1 // files made yesterday or earlier
xxcopy c:\mydir\* /RS /DA#0 // files made today (since midnight)
xxcopy c:\mydir\* /RS /DA#10H // files made within 10 hours
xxcopy c:\mydir\* /RS /DA#30M // files made within 30 minutes
xxcopy c:\mydir\* /RS /DA#90S // files made within 90 seconds
xxcopy c:\mydir\* /RS /DB#365 /S // include subdirectories

You may use an absolute value (/DA:yyyy-mm-dd , /DB:yyyy-mm-dd)

xxcopy c:\mydir\* /RS /DB:2002-10-31 // files made on or before
xxcopy c:\mydir\* /RS /DA:2001-11-01 // files made on or after
xxcopy c:\mydir\* /RS /DO:2000-01-01 // files made on the day
xxcopy c:\mydir\* /RS /DA:2001-01 // on or after 2001-01-01
xxcopy c:\mydir\* /RS /DA:2001 // on or after 2001-01-01
xxcopy c:\mydir\* /RS /DB:2001-12 // on or before 2001-12-31
xxcopy c:\mydir\* /RS /DB:2001 // on or before 2001-12-31
xxcopy c:\mydir\* /RS /DO:2001-12 // files made in 2001-12
xxcopy c:\mydir\* /RS /DO:2001 // files made during year 2001

I believe the above examples are sufficient to run the /RS (remove from
source) command in conjunction with /DA and /DB switches.

More common usage of XXCOPY is to copy files as the name implies.
In general, its command syntax is compatible with XCOPY. These are
a small fraction of what XXCOPY can do for you in variety of file
management operations.

XXCOPY is compatible with Windows 95/98/ME/NT/2K/XP. It comes with
XXCOPY16 with essentially the same set of switches for DOS environment.
One of the problems using a batch file is that it is difficult and messy
to write a good script that works well in all Windows versions.

Kan Yabumoto
The Author of XXCopy
======================================================================
"Gary Chan" <gary...@yahoo.com> wrote in message news:<03f501c2b37e$065c7910$d4f82ecf@TK2MSFTNGXA11>...

Jonathan de Boyne Pollard

unread,
Mar 14, 2003, 4:39:40 PM3/14/03
to
GC> Seems simple task to do in batch file but I have no idea
GC> what commands to use.

JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/common-tasks-with-jpsoft-clis.html#ProcessByDate>

V> This bit of batch [...]

Please _read_ the messages that you respond to.

V> [...] skipping the first 6 .log files (newest by date) then deles the rest.

At the very least, read their subject fields.

Jonathan de Boyne Pollard

unread,
Mar 14, 2003, 4:39:53 PM3/14/03
to
GC> Seems simple task to do in batch file but I have no idea
GC> what commands to use.

JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/common-tasks-with-jpsoft-clis.html#ProcessByDate>

PP> Delenda Cleanup Software lets you parameter [...]

Jonathan de Boyne Pollard

unread,
Mar 14, 2003, 4:37:55 PM3/14/03
to
KY> Since the built-in DEL (or ERASE) command does not allows you
KY> to specify the age of the file, [...]

This premise is only true for one particular vendor's command interpreter.

<URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/common-tasks-with-jpsoft-clis.html#ProcessByDate>

0 new messages