File Retention Policy in Windows 10
I'm an avid gamer. I have a drive dedicated to recordings of my games. My intention is to just record everything to this 500GB SSD and I only grab something if it's noteable. To accomplish this, I'd like to set a retention policy on a drive so any files older than... 12 hours get deleted.
Googling this is difficult because of the large number of Windows Server results. Is there some functionality or software I can use to accomplish this?
12 Answers
I would use either a batch script or a powershell script. After you create the batch file or powershell script you can create a scheduled task in Task Scheduler to run it let's say every 1 hour.
But I would probably use this for Command (only in whole days) Prompt:
forfiles -p "D:\Videos" -s -m *.* -d -1 -c "cmd /c del @path"In Powershell use this command (this will do hours):
Get-ChildItem -Path "D:\Videos" -Recurse -force -ErrorAction SilentlyContinue | where {$_.LastwriteTime -lt (Get-Date).AddHours(-12) } | Remove-Item -Verbose -Force -Recurse -ErrorAction SilentlyContinueJust replace D:\Videos with the actual directory of where those videos are restored. Replace the value 1 with how many days in the Batch Example. Replace the value -12 with how many hours old (retain the negative) and replace addHours with addMinutes or addMonths or addSeconds or addYears depending on what you want to do.
Good Luck!
1I recently answered an extremely similar question here
In short, you can use the standalone GNUWin32 build of the Linux "Find" command to delete any file older than X minutes.
Setup
- Download the binaries (findutils-4.2.20-2-bin) and dependencies (findutils-4.2.20-2-dep) .zip files from the link above.
- Extract and copy the contents of the dependencies folder to the binaries folder (feel free to overwrite).
- Rename find.exe in the "bin" folder (e.g. gnu_find.exe) to avoid conflicts with any Windows commands.
Assuming the above rename, the command to find and delete files 12 hours and older would be:
gnu_find.exe "C:\Path\To\Files" ! -mmin -720 -type f -deletewhere e.g. -720 represents a number of minutes (60*12 in this case). Do not leave off the ! (negation) option, since without it, files under (less than) 12 hours would be deleted.
Note that you can leave off -delete if you want to simply preview the files it will be working with.
GNUWin32 Find also supports a -name option which allows pattern matching with asterisks e.g.
gnu_find.exe "C:\Path\To\Files" ! -mmin -720 -type f -name "text*" -deleteCaveats About Name
- Be aware that -name should always appear before -delete or it will have no effect.
- You can use asterisks as you like for pattern matching (including in multiple positions) but be careful about including periods with asterisks (i.e if file extension matching is a concern, just use "filename*" or "*ext"). This has to do with how the Windows command line interprets things.
- You can find specific names (e.g. "filename.txt") but on Windows you must include the extension as GNUWin32 Find consider the whole filename string ("filename" <> "filename.txt")
Automation
You can use Task Scheduler to run thing automatically, but as I detail in the very first link, it may not be a preferable option. I personally recommend a Linux "cron"-style application (as detailed in that answer).
Windows 10
The above will likely work with any version of Windows, but up-to-date Windows 10 versions should have the ability to run an Ubuntu Linux sub-system. "find" and "cron" are extremely basic and should be available with this (though this version of "cron" seems tied to having a window open so may not be entirely suitable for your purpose).