Search : in
By :

BATCH DELETE

Last answer on May 21, 2009 12:44:15 am BST BARRYG, on Sep 23, 2008 1:29:50 pm BST 
 Report this message to moderators

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

Configuration: Windows Server 2000

Best answers for « BATCH DELETE » in :

1

logonserver, on Sep 23, 2008 7:33:57 pm BST

Hello,

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

http://www.wilsonmar.com/1wsh.htm

Reply to logonserver

2

bluenight, on Feb 18, 2009 3:03:15 am GMT
  • +1

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
 
 

Reply to bluenight

3

Rich, on Mar 26, 2009 3:33:33 pm GMT
  • +2

How easy would this be to change to be between a date range based on the modified date?

Regards

Rich

Reply to Rich

4

 StashO, on May 21, 2009 12:44:15 am BST
  • +1

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.

Reply to StashO