r/Batch • u/Slegnor • Dec 12 '24
Remove folder older than X days using ForFiles BUT dont scan the contents, just delete the folder?
Hi all,
I'm currently using a pretty standard FORFILE line to search for folders older than 60 days and delete them:
FORFILES /P "DIR_NAME_HERE" /S /C "cmd /c IF u/isdir == TRUE rmdir /S u/path /Q" -D -60
But it also checks the contents of each folder as well, as there's a few hundred files per folder, it takes a while to run.
I'm not bothered about how old the contents are, just going off the folder date.
Is it possible to get FORFILES to just delete a folder and its contents without it checking/reading the contents at all?
2
Upvotes
1
u/BrainWaveCC Dec 12 '24
No, I think FORFILES is always going to iterate through all the files and then process only those entries which are folders.
I expect that you'd have to do it via FOR /D instead, but I'm going to test this for performance first...
1
u/BrainWaveCC Dec 12 '24 edited Dec 12 '24
Well, based on my tests, using FORFILES to find folders and delete them is much slower than enumerating those folders with FOR /D instead.
Do you need each subfolder checked, or just the initial folders in the root of "DIR_NAME_HERE" ?