0

Is there a way I can create a batch file to delete files from a folder if they are in there for a certain number of days.

For example:

A files is in folder "edited" and has been there for a month, and if a file is in there for a month of longer, the batch file deletes it.

I'm guessing I would create a batch file then have it run on a schedule to check for files that have been there too long, I just don't know how to write the batch file.

Thanks in advance!

ddrossi93
  • 385
  • 2
  • 7
  • 19

1 Answers1

2

Googled a little, seems this is the solution:

forfiles -p "c:\your\folder" -s -m *.* /D -<number of days> /C "cmd /c del @path"

Change “C:\your\folder” to the directory to which you are saving the files you want to delete on a schedule. Note that the -40 refers to the day after which all files should be deleted so change the -40 if required.

Have a look at this post Batch file to delete files older than N days

Community
  • 1
  • 1
MadsTheMan
  • 705
  • 1
  • 10
  • 32
  • Do I have to schedule the batch file to run, or will it run automatically if a file is in there longer than x amount of time? – ddrossi93 May 22 '15 at 02:31
  • You'd have to schedule it. The other way would be to make a loop with a timeout involved. :) – MadsTheMan May 22 '15 at 05:03