-2

I am looking to make a simple batch file that will delete files and sub folders that are older than X days. I hope to schedule it for a daily run with task scheduler.

Windows 8.1

Eric
  • 71
  • 2
  • 11
  • Is there anything you've tried already that isn't working? If you don't know where to start, I suggest looking at `forfiles /?` – SomethingDark Feb 22 '15 at 04:26
  • 2
    possible duplicate of [Batch file to delete files older than N days](http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days) – SomethingDark Feb 22 '15 at 06:17

1 Answers1

0

Check this question. You can use the FileTimeFilterJS.bat or FileDateFilter.bat.They had pretty similar command line options but the first is based on jscript and the second jscript.net (and requires installed .NET Framework).Check the help messages for the details.This will delete files created 5 days ago (you can choose also modified date and last accessed date):

@echo off

for /f "tokens=* delims=" %%# in ('FileDateFilterJS.bat  "." -dd -5') do (

    echo deleting  "%%~f#"
    rem remove echo if the listed files are the ones you need
    echo del /q /f "%%~f#"
)

pause
Community
  • 1
  • 1
npocmaka
  • 55,367
  • 18
  • 148
  • 187