DELAGED batch command deletes specified
files of the specified directory which are older than specified maximum age
in days. Non-empty 3-rd parameter expands the scope of age-controlled
file deletion to all subdirectories of the specified directory.
Warning! DELAGED
command is potentially destructive and should be used with a great
caution. For experimenting with age-controlled mass file deletion
copy a directory tree of a reasonable size to a floppy disk and apply
DELAGED command only to that floppy. Don't apply DELAGED
command to your hard drive until you try it on floppy and are absolutely sure
that it works as you expect. If you don't have clear understanding what
to expect from DELAGED, i.e. if you are not sure how mass file deletion
works under DOS, please do not use DELAGED command at all.
Another safe way to experiment with DELAGED
is to comment out actual deletion lines and to uncomment the corresponding
ECHO lines (but still please start with a floppy — just in case...).
I.e. change block:
IFF %3.==. THEN
FOR %F IN (%DA1%%DA2%) (IF %@EVAL[%DA3% - %@DATE[%@FILEDATE[%F]]] GT %DA4% DEL %F)
: FOR %F IN (%DA1%%DA2%) (@ECHO IF %DA3% - %@DATE[%@FILEDATE[%F]] GT %DA4% DEL %F)
ELSE
IF %@UPPER[%3]==Y SET DA6=/Y
FOR /R %DA1% %F IN (%DA2%) (IF %@EVAL[%DA3% - %@DATE[%@FILEDATE[%F]]] GT %DA4% DEL %F %DA6%)
: FOR /R %DA1% %F IN (%DA2%) (@ECHO IF %DA3% - %@DATE[%@FILEDATE[%F]] GT %DA4% DEL %F %DA6%)
ENDIFF
into a block with actual deletion completely disabled:
IFF %3.==. THEN
: FOR %F IN (%DA1%%DA2%) (IF %@EVAL[%DA3% - %@DATE[%@FILEDATE[%F]]] GT %DA4% DEL %F)
FOR %F IN (%DA1%%DA2%) (@ECHO IF %DA3% - %@DATE[%@FILEDATE[%F]] GT %DA4% DEL %F)
ELSE
IF %@UPPER[%3]==Y SET DA6=/Y
: FOR /R %DA1% %F IN (%DA2%) (IF %@EVAL[%DA3% - %@DATE[%@FILEDATE[%F]]] GT %DA4% DEL %F %DA6%)
FOR /R %DA1% %F IN (%DA2%) (@ECHO IF %DA3% - %@DATE[%@FILEDATE[%F]] GT %DA4% DEL %F %DA6%)
ENDIFF
This change will cause DELAGED command
to list deletion conditions and corresponding files instead of performing
actual age-controlled file deletion.
Demo of DELAGED
command operation can be found below the command text.
: DELAGED Delete Files Older than Specified Age (Days) 10/04/1995-10/15/1999
: ----------------------------------------------------------------------------
: Copyright (C) 1995-1999 by Vladimir Veytsel www.davar.net
: 1. Contents [and filespec] to be processed (Default: Entire current direct)
: Symbol "#" should be used as a placeholder (stands for the entire curr dir)
: when it is necessary to specify the following parameter[s] with 1-st defaulted
: "?" - Display batch command text (Equivalent: "/")
: Note: When only directory is specified (without filespec)
: it should be closed by "\"; E.g.: A:\ or A:\BATCH\
: 2. Maximum file age (days) for a file to be kept (older files are deleted)
: (Default: 30 days) ^^^^
: Symbol "#" should be used as a placeholder (stands for the age of 30 days)
: when it is necessary to specify the 3-rd parameter with 2-nd being defaulted
: 3. Non-empty value indicates that path part of the first parameter specifies
: the directory to start deletion from and then proceed through all of its
: subdirectories (Default: Delete aged files only within specified direct)
: E.g.: DELAGED - Delete all files in current directory
: that are older than 30 days
: DELAGED #,7 - Delete all files in current directory
: that are older than 7 days
: DELAGED A:\BATCH\ - Delete all files in A:\BATCH direct
: that are older than 30 days
: DELAGED A:\CLIENT\MISCL\,10 - Del all files in A:\CLIENT\MISCL\ dir
: that are older than 10 days
: DELAGED A:\REFER\*.BKM,#,S - Del *.BKM files in A:\REFER directory
: (and in all of its subdirectories)
: that are older than 30 days
@ECHO %TR%
IF %1.==/. .OR. %1.==?. (LIST %_BATCHNAME ^ QUIT)
SET DA2=%1 ^ IF %DA2%.==#. .OR. %DA2%.==. SET DA2=%_CWD\*.*
SET DA1=%@PATH[%DA2%] ^ IF %DA1%.==. SET DA1=%_CWD\
SET DA2=%@FILENAME[%DA2%] ^ IF %DA2%.==. SET DA2=*.*
SET DA3=%@DATE[]
SET DA4=%2 ^ IF %DA4%.==#. .OR. %DA4%.==. SET DA4=30
IF NOT %3.==. SET DA5= (including %Y%subdirs%W%)
@ECHO %W%Deleting %G%%@UPPER[%DA1%%DA2%] %W%files%DA5% that are older than %C%%DA4%%W% days%D%
IFF %3.==. THEN
FOR %F IN (%DA1%%DA2%) (IF %@EVAL[%DA3% - %@DATE[%@FILEDATE[%F]]] GT %DA4% DEL %F)
: FOR %F IN (%DA1%%DA2%) (@ECHO IF %DA3% - %@DATE[%@FILEDATE[%F]] GT %DA4% DEL %F)
ELSE
IF %@UPPER[%3]==Y SET DA6=/Y
FOR /R %DA1% %F IN (%DA2%) (IF %@EVAL[%DA3% - %@DATE[%@FILEDATE[%F]]] GT %DA4% DEL %F %DA6%)
: FOR /R %DA1% %F IN (%DA2%) (@ECHO IF %DA3% - %@DATE[%@FILEDATE[%F]] GT %DA4% DEL %F %DA6%)
ENDIFF
UNSET DA1 DA2 DA3 DA4
SET DA5=
SET DA6=
Dummy deletion of all files from A:\PC\ directory that are older than 30 days.
Wed 10/13/99 20:02 C:\> DELAGED A:\PC\,30
Deleting A:\PC\*.* files that are older than 30 days
IF 7225 - 7222 GT 30 DEL A:\PC\ABOUT.HTM
IF 7225 - 7074 GT 30 DEL A:\PC\BIBLIOGR.HTM
IF 7225 - 7106 GT 30 DEL A:\PC\LINKS.HTM
Actual deletion of all files from A:\PC\ directory that are older than 30 days.
Wed 10/13/99 20:02 C:\> DELAGED A:\PC\,30
Deleting A:\PC\*.* files that are older than 30 days
Deleting A:\PC\BIBLIOGR.HTM
1 file deleted 2,048 bytes freed
Deleting A:\PC\LINKS.HTM
1 file deleted 11,264 bytes freed
Dummy deletion of all files from A:\ root directory (and subdirs) that are older than 30 days.
Wed 10/13/99 20:02 C:\> DELAGED A:\,30,S
Deleting A:\*.* files (including subdirs) that are older than 30 days
IF 7225 - 7185 GT 30 DEL A:\ABOUT.HTM
IF 7225 - 7074 GT 30 DEL A:\BIBLIOGR.HTM
IF 7225 - 7222 GT 30 DEL A:\INDEX.HTM
IF 7225 - 7104 GT 30 DEL A:\SEARCH.HTM
IF 7225 - 7222 GT 30 DEL A:\PC\ABOUT.HTM
IF 7225 - 7074 GT 30 DEL A:\PC\BIBLIOGR.HTM
IF 7225 - 7106 GT 30 DEL A:\PC\LINKS.HTM
IF 7225 - 7224 GT 30 DEL A:\PC\4DOS\4DOS.HTM
IF 7225 - 7222 GT 30 DEL A:\PC\4DOS\ABOUT.HTM
IF 7225 - 7211 GT 30 DEL A:\PC\4DOS\DELAGED.BTM
IF 7225 - 7225 GT 30 DEL A:\PC\4DOS\DELAGED.HTM
IF 7225 - 7211 GT 30 DEL A:\PC\4DOS\INSERT.BTM
IF 7225 - 7214 GT 30 DEL A:\PC\4DOS\INSERT.HTM
IF 7225 - 7211 GT 30 DEL A:\PC\4DOS\SETCOLOR.BTM
IF 7225 - 7218 GT 30 DEL A:\PC\4DOS\SETCOLOR.HTM
IF 7225 - 7211 GT 30 DEL A:\PC\4DOS\TR.BTM
IF 7225 - 7214 GT 30 DEL A:\PC\4DOS\TR.HTM
Actual deletion of all files from A:\ root directory (and subdirs) that are older than 30 days.