| 1. |
Solve : Batch Script to Delete The Oldest Folder With a Specifc Name? |
|
Answer» I spent a little time on this one a can't seem to find exactly what I need. I don't have anything to OFFER because I'm truly stumped. I have 3 folders named like this: Foxidrive. Thanks, I modified it to -d It's not creation date though, and that could be what the OP wants. This is the same thing but sorted by creation date. Code: [Select]@echo off for /f "delims=" %%a in ('dir "rox*" /t:c /a:d /o:-d /b') do set "folder=%%a" echo rd /s /q "%folder%" pause And yes, foldernames with ROX-YYYYMMDD are certainly preferable to sort by.Thank you! Works like a charm. I appreciate it. It's inspired me to take it a step further. How can I run the loop against a text file that contains a list of servers? Text file will include computer names: Computer1 Computer2 Computer3 etc. . . . Do I SIMPLY place the path to the text file in the parenthesis ("" ' dir "Rox*" . . . )? Thanks again, MJPerhaps I can nest the for loops like this: Code: [Select]For /F "Tokens=*" %%I IN (textfile.txt) DO ( for /f "delims=" %%a in ('dir "\\<path-to-\Rox*" /t:c /a:d /o:-d /b') do set "folder=%%a" rd /s /q "%folder%" Will that work? |
|