Deleting files after a certain period of time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pjmsijm
Posts: 1
Joined: 08 Nov 2013 01:24

Deleting files after a certain period of time

#1 Post by pjmsijm » 08 Nov 2013 01:33

Hello,

I want to delete files after a certain period of time after the files are created.

So i am thinking about a batch file that runs all the time and checking wether one or more files in a folder exists longer than a given period (lets say 15 minutes) and then delete the file(s).

Is there anyone who can help me with this?

With kind regards,

Peter

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Deleting files after a certain period of time

#2 Post by ShadowThief » 08 Nov 2013 02:12

Anything period of time less than one day means you have to manually calculate the age of the file, which is a hassle. If you want to remove all files over one day old, you can just use something like

Code: Select all

forfiles /p <path> /C "cmd /c del @path" /d -<time>


Fortunately I've needed a script that does 15 minutes before, but it's not on this computer so I'll post it when I have it. If somebody with "Expert" under their name posts code before I do, go with theirs.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Deleting files after a certain period of time

#3 Post by foxidrive » 08 Nov 2013 03:37

XXcopy has finer granularity and can use the /L switch to just list the files, which can be processed in a for /F loop.

www.xxcopy.com

Post Reply