windows 7 - Create a folder in Win 7 where files will be deleted after a specified period automatically
2014-04
I would like to have a folder to put items for temporary use. Is this possible in Windows 7? Some sort of .bat
file in startup? But I would prefer doing it without restart. Any hints?
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
So i have a folder where i sometimes get few big files after doing some work.Problem is that every time i have to go and delete them manually.I know it's possible to delete them after 1 day or more but i would like to be able to delete them if they have been modified in the last few hours.
To further complicate matters there are other files in that folder that i do NOT want to delete and to complicate things even further they all have very similar yet unpredictable filenames.Meaning i cant just use del to delete the newest ones but i have to rely on modify date.
Can it be done in Win7?
find /some/dir -type f -mmin -<minutes old> -print0 | xargs -0 rm
This finds all items under /some/dir
that are files and are less than <minutes old>
minutes old, and removes them. Don't forget the -
before the number of minutes. Also, if mmin doesn't do the trick, try cmin.
IIRC the Windows Explorer can sort by modification time, so you could do that and select the files that were modified in the desired time range.
slartibartfast has given an answer that assumes you have Unix-like utilities installed. On Windows, this could be cygwin or GNU Win32 utilities or Microsoft Windows SFU or UWIN. If you install one of these, make sure to use its find
and not the unrelated native Windows command.