@echo off&SETLOCAL :: DELOLDER.cmd days fullpath :: :: For example: :: DELOLDER 14 C:\temp\*.* :: DELOLDER 28 "C:\Log Files\" :: DELOLDER 28 "C:\Log Files\*.LOG" :: note: do not specify the Current Directory :: To use this batch for real, edit the last line below :: i.e. change [ECHO DELETE the file] to [DEL] or [MOVE] or whatever SET v_days_newer=%1 SET v_source=%2 :: get todays date from getdate.cmd CALL GetDate SET yy=%yy:~2,2% :: calculate new date using DateMath.cmd CALL DateMath %yy% %mm% %dd% - %v_days_newer% ECHO Files older than Year: [%v_yy_int%] Month: [%v_mm_str%] Day: [%v_dd_str%] :: Compare each file in the DIR with files that are newer than day X :: and delete all those that don't match (ie are older) FOR /f "tokens=*" %%G IN ('XCOPY %v_source% /L ^| FIND "\"') DO CALL :s_match_older "%%G" goto :eof :s_match_older FOR /f "tokens=*" %%G IN ('XCOPY %v_source% /D:%v_mm_str%-%v_dd_str%-%v_yy_int% /L ^| FIND "\"') DO IF %1=="%%G" (GOTO :eof) ECHO DELETE the file %1