BATCH DELETE

Closed
BARRYG - Sep 23, 2008 at 08:29 AM
 boy_socola08 - May 23, 2010 at 06:48 AM
Hello,I wish to create a Windows 2000 batch file that will search through a folder structure and delete any type of file that is older than 30 days - Please could someone supply a script - Thanks

3 responses

C:\scripts>more cleanup_display.bat
@ECHO OFF
SETLOCAL

SET targetPath=C:\scripts\scripts\logs
SET targetFiles=*.log
SET aMonthBefore=20090214

FOR /f %%z IN ('dir /b %targetPath%\%targetFiles%') DO (
  FOR /f "tokens=1-4 delims=/ " %%a IN ('dir %targetPath%\%%z') DO (
    IF "%%c%%a%%b" LSS "9" (
      FOR /f "tokens=1-4 delims=(" %%1 IN ("%%c%%a%%b") DO (
        IF "%%2"=="" (
          IF %%c%%a%%b LSS %aMonthBefore% (
            ECHO Detect file older than %aMonthBefore% ::::: -- %%z -- %%c%%a%%b
          ) ELSE (
            ECHO Defect file newer than %aMonthBefore% ::::: -- %%z -- %%c%%a%%b
          )
        )
      )
    )
  )
)


C:\scripts>dir C:\scripts\scripts\logs\*.log
 Volume in drive C has no label.
 Volume Serial Number is 0D38-406F

 Directory of C:\scripts\scripts\logs

07/22/2008  08:50 PM            16,640 bck_20080722.log
07/24/2008  03:36 PM             1,067 bck_20080724.log
02/18/2009  11:07 AM                 0 msms.log
               3 File(s)         17,707 bytes
               0 Dir(s)  47,139,299,328 bytes free

C:\scripts>cleanup_display.bat
Detect file older than 20090214 ::::: -- bck_20080722.log -- 20080722
Detect file older than 20090214 ::::: -- bck_20080724.log -- 20080724
Defect file newer than 20090214 ::::: -- msms.log -- 20090218
 
 
4
How easy would this be to change to be between a date range based on the modified date?

Regards

Rich
0
This is great but can the /S e added to the DIR statements to get all the files in the undelying directories at the same time? When I tried adding /S I get an error.

Thanks.
0
logonserver Posts 5 Registration date Sunday August 31, 2008 Status Member Last seen March 31, 2009 12
Sep 23, 2008 at 02:33 PM
hello,

here is a link which might help you for the batch file you are willing to create :

http://www.wilsonmar.com/1wsh.htm
1
hello. All
help me!
dos command(.bat or .vbs ) script It first notified in 30 days. every time you sign in with prison time will dem crossbred 31,30,29 ,.... ,0 .It immediately expire Examination
1