The last action is to remove the trash folder containing all found old files which. You exclude multiple folders with the /XD switch. Robocopy will than move (not copy!) all desired files (correct extension and modified time stamp older than 365 days) to that trash folder. The batch will create a temporary trash folder named TrashMe. Robocopy C:\ C:\TrashMe *.cfg *.hdr *.txt *.dat /MOVE /E /MINAGE:365 /CREATE /R:1 /W:1 /XD C:\dir1 C:\dir2 C:\TrashMe You can misuse Robocopy to delete old files, filter for certain extensions and exclude multiple directories from scanning - all in one command. Nevertheless I want to share what I have found. And if the blacklisted folders list grow my Robocopy command will look ugly. I think MBu's answer is better than mine since it doesn't rely on an external tool like Robocopy. I am afraid it may break on folder names containing special characters like % or ^. The file should contain full paths to excluded folders without quotes: D:\excluded folder1įor each folder that is not blacklisted a subroutine is called which searches for files based on extension and then each file's date is compared with the date given. The blacklist should be stored in blacklist.txt file in the same directory where the script resides. I had to get rid of /r switch and call a subroutine recursively or the blacklist would not work properly. I think I have managed to modify the script to work the way you want. If not, the comparison will not work as expected. You can try this script but it will work only if %%~tA in your regional settings is returning the file date using YMD format.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |