Remove All Files That Are Older Than

Read Time:29 Sec

The following bat file will delete all files in a directory and its subdirectories that are have a modified date older than 2 years:

 
@ECHO OFF 
REM *** DELETE FILES OLDER THAN 2 YEARS 

REM *** GET TODAYS DATE 
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
 	Set Month=%%A
 	Set Day=%%B
 	Set Year=%%C
) 

REM @echo DAY = %Day% 
REM @echo Month = %Month% 
REM @echo Year = %Year% 

REM *** SUBTRACT 2 FROM THE CURRENT YEAR 
set /a Year2=%Year%-2 

forfiles /p "E:\IIS6LOGFILES" /s /m *.log /d -%Month%/%Day%/%Year2% /c "cmd /c del @path"

Author

Stewart Schatz

Career: Principal CNC Consultant for Syntax Systems Limited specializing Oracle JD Edwards EnterpriseOne and the technology that supports it. Side Hustle: Owner/Operator of E1Tips.com Location: Lancaster, PA USA  What I like to do: Invest in Family, Explore Technology, Lead Teams, Share Knowledge/Experience, Hunt, Hike, etc.
Happy
Happy
0
Sad
Sad
0
Excited
Excited
0
Sleepy
Sleepy
0
Angry
Angry
0
Surprise
Surprise
0

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Previous post JDE vs SAP… JDE Wins On Total Cost of Ownership!
Next post Oracle JDE EnterpriseOne Now Supports the iPad