Just to add to this
With forfiles, if your filename has spaces, you need to put quotes around
it.
Below is a wrapper bat file I wrote for forfiles to make it somewhat easier
to use (and shorter to call from elsewhere).
Also, this wrapper shows an example of only deleting if it is a file and not
a dir.
Have fun,
Bruce Reardon
-------------------
@echo off
rem PURPOSE
rem delete_oldfiles.bat
rem deletes files greater than or equal to x days old
rem Note - directories are not deleted.
rem does not delete read only, hidden or system files
rem 18-Apr-2000 , Bruce Reardon : Creation.
rem USEAGE
rem Parameters - %1 = path , %2 = file mask ,
rem %3 = how many days old , %4 (optional) - recurse
rem ASSUMPTIONS
rem none.
rem REQUIRES
rem forfiles.exe - distributed with NT Resource kit
rem that forfiles.exe be located at c:\nt4reskit
rem SIDE EFFECTS
rem envdelold env variable will be overwritten and deleted if it exists.
rem MODIFICATIONS
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem Parameter validation.
IF "%3"=="" goto param_problem :: not enough params
IF NOT "%5"=="" goto param_problem :: too many params
rem check parameter 3 is a valid number
set envdelold=
IF "%3"=="0" goto param3_ok
set /a envdelold = 1*%3 2> nul:
IF "%envdelold%"=="0" goto param3_problem
IF "%envdelold%"=="" goto param3_problem
:param3_ok
IF NOT "%4"=="" IF NOT "%4"=="-s" goto param4_problem :: invalid param 4
IF NOT EXIST %1. goto param1_problem
rem we now have 3 (possibly 4) parameters and they have been
validated.
echo %1 %2 %3 %4
rem the actual command - put quotes around to allow for names with
spaces.
c:\nt4reskit\forfiles -p%1 -m%2 %4 -d-%3 -c"cmd /c if @ISDIR==FALSE del
0x22@FILE0x22"
goto end
:param_problem
echo %0
echo ERROR - Must pass in 3 parameters (4 max)
echo Param 1 is the path
echo Param 2 is file mask
echo Param 3 is number of days
echo Param 4 (optional) : if "-s" then recurse subdir's.
echo.
echo eg "%0 c:\temp *.* 5" would delete ALL files in c:\temp directory 5
or more days old
goto end
:param1_problem
echo "%0 [-->[%1]<--] %2 %3 %4"
echo ERROR - 1st parameter invalid
echo Param 1 is the path and it must exist.
echo.
echo eg "%0 c:\temp *.* 5" would delete ALL files
echo in c:\temp directory 5 or more days old
goto end
:param3_problem
echo "%0 %1 %2 [-->[%3]<--] %4"
echo ERROR - 3rd parameter invalid
echo Param 3 is the number of days and it must be a valid number
echo.
echo eg "%0 c:\temp *.* 5" would delete ALL files
echo in c:\temp directory 5 or more days old
goto end
:param4_problem
echo "%0 %1 %2 %3 [-->[%4]<--]"
echo ERROR - 4th parameter invalid
echo Param 4 (optional) : must be "-s" (to recurse subdir's) or be
blank.
echo.
echo eg "%0 c:\temp *.* 5 -s" would delete ALL files
echo in c:\temp directory (incl subdirs) 5 or more days old
goto end
:end
rem - batch file finished
set envdelold=
----------------------------------------------
-----Original Message-----
Sent: Thursday, 24 May 2001 8:31
Raj,
If you have the resource kit installed you can use forfiles.
forfiles -pp:\zipfiles\hot\ -s -m*.* -d-20052001 -c"CMD /C DEL /Q @FILE";
Forfiles is helpful for ton's of DB Maintenance, you can pipe the results to
any dos command you want.
We use a statement like the one below in our spool_Hot_Backup script
to prune the backup directories before we put all the tablespaces in hot
backup mode and ocopy them, We then compress them in a staging directory
using pacomp and move them to a drive so that last nights datafiles are
around for a speedy recovery (If Necessary).
/* Clean Out ZIP Files older than two days: Uses Forfiles Resource
Kit*/
select to_char(sysdate-2,'ddmmyyyy') into datestr from dual;
dbms_output.put_line('host forfiles -p'||backupdir||' -s -m*.*
-d-'||datestr||
' -c'||chr(34)||'CMD /C DEL /Q @FILE'||chr(34)||';');
HTH, (hazardous terminal halitosis)
Scott Crabtree
-----Original Message-----
Sent: Wednesday, May 23, 2001 11:45 AM
DBAs
How do I delete files from NT which are older than a week. I need this to
organise my backup dump files.
Cheers
Raj
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Reardon, Bruce (CALBBAY)
INET: [EMAIL PROTECTED]
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
San Diego, California -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).