Create a folder in Win 7 where files will be deleted after a specified period automatically

0

I would like to have a folder to put items for temporary use and after a certain amount of time they would be deleted

Is this possible in Windows 7?

I've through of maybe some sort of .bat file in startup? But I would prefer doing it without restart.

Can a task be scheduled to achieve the desired effect?

Mihai

Posted 2014-02-01T09:58:18.103

Reputation: 125

Using a cronjob or a scheduled task (in the Windows world) would solve the problem without being dependent on any starts or logins. Is a single file age for automatic deletion for the whole folder sufficient for you? – pabouk – 2014-02-01T11:07:53.460

@pabouk Sure,as long as it is created date,that is,the date when I move it in the respective folder.I`m running now wmz solution,and it works only that it takes into account the modified date. – Mihai – 2014-02-01T11:10:50.487

Answers

3

You could use forfiles to enumerate and process files not modified longer than (or since date), for example (as shown on linked MS page - this would simply list them)

forfiles /s /m *.* /d -365 /c "cmd /c echo @file is at least one year old."

After you've verified it works as you'd want it to, put it in a batch file and schedule using Task Scheduler (or use schtasks if you prefer command line).

[Edit]

If creation date (not modification) date is required, I would resort to powershell: This one liner gets and prints all files created earlier that 365 days.
Please note it does not strip times from dates (so comparison takes not only date, but also time of creation and time when it runs)!

powershell -command "gci |? {$_.CreationTime -lt (get-date).addDays(-365)} |% {write $_}"

To delete instead of list, replace write with del
To strip time from dates, use (get-date).date You may also want to exclude folders from processing

wmz

Posted 2014-02-01T09:58:18.103

Reputation: 6 132

How can I delete files based on created date not on modified date?Although most of the times these will be the same. – Mihai – 2014-02-01T10:58:06.107

@Mihai What you want (and Date&time arithmetic) is rather difficult/problematic in pure batch/cmd. While it is possible [to achieve] I would use powershell for that. See my update. – wmz – 2014-02-01T12:30:09.063