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

Linux command: Check Current Shell

What is your current shell ?

Java: Free Online Courses

The Java™ Tutorials by Oracle The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. They include hundreds of complete, working examples, and dozens of lessons. Groups of related lessons are organized into "trails". https://docs.oracle.com/javase/tutorial/ Learn to Program in Java at edX.ogr Get started on the path to becoming a software engineer by learning core coding skills in Java—one of the most popular programming languages. https://www.edx.org/course/learn-to-program-in-java-0 Java Tutorial by javapoint.com https://www.javatpoint.com/java-tutorial Java Tutorial by SoloLearn.com I love SoloLearn because I can learn Java - and other popular programming languages - anywhere, any time on your mobile devices. https://www.sololearn.com/Course/Java/ Java on Azure https://docs.microsoft.com/en-us/learn/paths/java-on-azure/

Powershell: Get-ChildItem

List, search/find files and directories with Get-ChildItem cmdlet.