I found a really old post suggesting using xcopy to copy the newest (presumably the ones to keep) files to a temp location, then delete the original files, then move those copied away back to their original location. This approach had some promise, but had some real drawbacks too; particularly that I'm dealing with tens of gigabytes & this would take forever, and that I'm dealing with several and varying subdirectories.
Since xcopy has been deprecated and replaced with robocopy in Windows 2008, Windows 7, etc. that's what I chose to use. In fact, robocopy has a couple switches that make it easy to move (/MOV) files older than x days (/MINAGE:x).
What I ended up with was a simple two line batch file that I'm using Windows task scheduler to run once a day. The first line moves files older than x days to a temporary location & the second line deletes the moved files.
robocopy D:\Original_Location D:\DelOldFiles * /S /MOV /MINAGE:7
del D:\DelOldFiles\* /s /q
Breakdown
The robocopy syntax is ROBOCOPY source destination [file [file]...] [options]. I'm using the following switches (options):
The robocopy syntax is ROBOCOPY source destination [file [file]...] [options]. I'm using the following switches (options):
- /S - include subdirectories
- /MOV - move (which is technically a copy, then delete original)
- /MINAGE:x - act on files older than x days
After the files are moved I'm deleting all files (*), in all subdirectories (/s) in my temp folder, quietly (/q), i.e. don't prompt, just do it.
See also
See also
Using dos to delete based on date
No comments:
Post a Comment