Gokul's Blog

Deleting files older than X days

Leave a comment


@echo off
set BACKUP_PATH=%1
set RET_INTERVAL=%2
set FILE_FILTER=%3
if "%BACKUP_PATH%"=="" exit 1
if "%RET_INTERVAL%"=="" exit 1
Forfiles /P %BACKUP_PATH% /S /M %FILE_FILTER% /D -%RET_INTERVAL% /C "cmd /C Del @path"
exit
%ERRORLEVEL% Usage: DelOldFiles.bat C:\Backup 10 *.xml

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s