I am looking for a simple bat script to delete files in a directory older than, say, 7 days. Its for automatic mail log file
deleting.
Cant seem to find anything suitable on the net.
Can anyone help?
Thansk
Laurie
Laurie
"laurie" <law...@hotmail.com> wrote in message news:d3fec.678$P%3.342@newsfe1-win...
In that case news:alt.msdos.batch.nt is your thing.
There e.g. the reverse of
8} How do I find all the files made at of after YYYYMMDD HHMM?
94268 Mar 31 2004 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
Here in alt.msdos.batch which is for MS-DOS+Win../95/98/Me the task
is much more tricky.
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip
> Oh, and it's Windows 2000 Server.
> I am looking for a simple bat script to delete files in a directory older
> than, say, 7 days. Its for automatic mail log file deleting.
Forfiles can be found at
ftp://ftp.microsoft.com/ResKit/y2kfix/x86/forfiles.exe
@echo off
if not "%3"=="" goto start
echo.Purpose: to delete specified files that are n days or older
echo. in the folder specified on the command line.
echo. (if -s is used it will include all subdirectories as well)
echo.
echo. NOTE 1: Currently it only prints the del command to the screen so
echo. remove the word ECHO from set p2= to activate it, after testing.
echo.
echo. Syntax: %0 "Drv:\Folder Name" "filespec.ext" number_of_days [-s]
echo.
echo.Example: %0 "C:\Program Files\Data" "*.zip" 8 -s
echo.
echo. will delete *.zip files 8 days and older
echo. from the "C:\Program Files\Data" folder
echo. and recurse through the DATA Folders subdirectories too.
echo.
echo. NOTE 2: The "Drive:\Folder Name" and "filespec.ext" should be
echo. "enclosed in DOUBLE QUOTES"
echo.
echo. Compatible with Win9x/ME/NT/W2K/XP
echo.
echo. Forfiles can be found at
echo. ftp://ftp.microsoft.com/ResKit/y2kfix/x86/forfiles.exe
goto end
:start
set p1=%comspec% /C if not @ISDIR
set p2=ECHO del 0x22@PATH\@FILE0x22
::
:: the following 3 lines will write a log file (remove if not needed)
echo Writing log file, please wait...
if exist c:\log.txt del c:\log.txt
FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1%==TRUE echo %p2% >>c:\log.txt"
::
echo Deleting, please wait...
FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1%==TRUE %p2%"
echo Done!
for %%a in (p1 p2) do set %%a=
:end
> I am looking for a simple bat script to delete files in a directory
: older than, say, 7 days.
>
> Laurie
*** Try XXCOPY. I think the syntax is:
XXCOPY drive:\directory\*.* /DB8 /RS
You may want to add other switches to tailor that. An XXCOPY link is in
my "DOS Websites" directory at:
http://www.chebucto.ns.ca/~ak621/DOS/Websites.html
You might also find the final version of BU.bat useful. It's at:
www.chebucto.ns.ca/~ak621/DOS/Bat-Adv2.html
Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
I have used other solutions on the XP-line, but have occasionally
tried forfiles on Win95. There is one thing that baffles me about
that program. My time zone is +2 (in winter). On my 95 forfiles
identifies the number of days (by one) incorrectly at midnight +2
hours! Therefore, I've avoided using it when I have other options.
Here is a simple method that uses pkzip.exe, but requires a user
supplied date.
:: delbydat.bat (delete by date)
@echo off
if "%2"=="" echo. parm1 is date
if "%2"=="" echo. parm 2 is filespec for targeted files
if "%2"=="" goto end
if not exist %2 echo. must be valid filespec
if not exist %2 goto end
echo. Files %2 dated before %1 will be deleted...
choice.com/cyn/tn,4 " are you sure "
if errorlevel 2 goto end
pkzip -T%1 -m-r %temp%\delete.me %2
del %temp%\delete.me
:end
Unwise to post in this group, then; it is for DOS..Win98/ME.
>I am looking for a simple bat script to delete files in a directory older than,
>say, 7 days.
You are saying that the directory must be older than 7 days, but
probably mean the files must be older than 7 days.
> Its for automatic mail log file
>deleting.
>Cant seem to find anything suitable on the net.
Improved searching technique required, then.
In any DOS-like batch system,
HUNT * b#-7 "del" u ; omit u for test
will delete before the beginning of the day 7 ago;
NOWMINUS d7 Eweekago
HUNT * b%weekago% "del" u ; omit u for test
will delete before this time seven days ago, in on-topic systems.
HUNT * D b#-7 "del " + "\*.*" u ; omit u for test
will delete all unprotected files from all aged directories.
HUNT, NOWMINUS via sig line 3.
However, WSH might provide a better solution for use in Win2K.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
// go to bed earlier, then !! <G>
Presumably it is using UTC/GMT dating; the GMT date changes in Finland
at local 0200h in winter and 0300h in summer.
The traditional DOS date-stamp is implicitly local time, knowing nothing
of zone; but the stamps added in Windows are in units of 100 ns from
1601-01-01 00:00:00 GMT (I don't know whether 95 might have implemented
that differently).
Perhaps forfiles makes the opposite error in the evening for those in
the New World?