Skip to main content

Delete files older than 365 days

I must delete IIS *.log files in  older than 365 days.

D:\Logs
|
-W3SVC1
-W3SVC2
-...
-W3SVC33


daily-delete-logfiles-older-than-365-days.cmd

:: Daily delete log files older than 365 days
:: Created on: 20161120
:: Created by:
:: Last modified on:
:: Last modified by:
:: History:

SET DIRLOG=E:\_scripts\Logs\
:: Echo @path to test first
:: FORFILES /P D:\Logs /S /M *.log /D -365 /C "cmd /c echo @path @fdate"
:: Delete files
ECHO "Begin" >> %dirlog%daily-delete-logfiles.log
DATE /T >> %dirlog%daily-delete-logfiles.log
TIME /T >> %dirlog%daily-delete-logfiles.log
FORFILES /P D:\Logs /S /M *.log /D -365 /C "cmd /c del @path" >> %dirlog%daily-delete-logfiles.log
ECHO "Finished" >> %dirlog%daily-delete-logfiles.log
DATE /T >> %dirlog%daily-delete-logfiles.log
TIME /T >> %dirlog%daily-delete-logfiles.log
:: END of script


/P : Path to folder
/S: recurse into subdirectories
/M *.log: Match *.log files
/D -365: files older than 365 days
/C: run command
@path: full path of files

Popular posts from this blog

IIS: Delete cached files on server running IIS

Delete cached files on server running IIS When changing css, javascript files, check to delete if IIS still caches old files in the default folder C:\inetpub\temp\IIS Temporary Compressed Files\<sitename>\$^_gzip_D^\ Apply to: IIS 8.5

Linux command: du - disk usage

Where have all my storage gone? du summarize disk usage of the set of FILEs, recursively for directories.

ManageEngine ServiceDesk Plus - Reset password

Let's reset the default administrator's password to 'admin'