Pages

Monday, April 12, 2021

cmd bat script to delete files in a directory olden than X days

@echo OFF

REM cd D:\SfiGen\ArchiveDir
SET DEL_DIR=D:\SfiGen\ArchiveDir
SET WORK_DIR=
D:\SfiGen\scripts
SET KEEP_DAYS=30

ECHO start delete files from  %DEL_DIR% older than %KEEP_DAYS% days

cd %DEL_DIR%
forfiles /p %DEL_DIR% /s /d -%KEEP_DAYS% /c "cmd /c del /Q @file"
ECHO Files Deleted
cd %WORK_DIR%


No comments:

Post a Comment