Wednesday, November 16, 2022

Why and How to delete and compact files Windows?

Why ?

To use a CMD code (.bat) that delete files older than x days and/or use a compact windows feature ( compact) use the below code as a sample to achieve this goal.

How ?

Below is a Windows CMD code that will cleanup/delete files and compact other files based on age, in my below code example I will delete files older than 180 days and compact(compress) files older than 2 days in specific path with certain file pattern naming:

1- Code below:

:: Delete All Archives older than 6 months (1 weeks for client logs)

 

echo %DATE% %TIME%

 

forfiles /p "E:\Avanza\Logs\Svc" /s /m PayHub_*.log /c "cmd /c Del @path" /d -180

forfiles /p "E:\Avanza\Logs\Svc" /s /m PayHub_*.log /c "cmd /c if @isdir==FALSE Compact /c @path" /d -2

No comments:

Post a Comment

Why and How to install Grid 19c on RHEL 8?

  Why ? Simply we will be requested to install Oracle Grid RAC DB on Redhat RHEL 8, below is my note for this installation . How ? 1-  OS in...