I 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 -delete
where 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*" -delete
Caveats 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).