You are not logged in.
I have a folder tree like this, (it's only an example).
C:\TEST
├───Test1
│ └───Test
├───Test2
│ └───Test
└───Test3
└───Test
How do I recursively rename all Test directories using a batch-file?
Offline
There are a few ways to skin this cat.
Here's one which I think would work (not tested):
for /f "usebackq tokens=*" %%D in (`dir /a:d/b/s "C:\TEST" ^| findstr /l/i/e "\\Test"`) do rename "%%~D" "%%~dpD\NewName"
EDIT: Oh, in the example you've given I think that will probably rename the top level directory, because it has the same name as the directory you are searching for.
This, I think, should make sure you only match on a sub-directory that is not your top level (again, untested):
set TOPLEVEL="C:\TEST"
set MATCH="Test"
for /f "usebackq tokens=*" %%D in (`dir /a:d/b/s "%TOPLEVEL%" ^| findstr /l/i/e "%TOPLEVEL:\=\\%\\.*\\Test"`) do (
rename "%%~D" "%%~dpD\NewName"
)
Last edited by bluesxman (23 Sep 2019 09:09)
cmd | *sh | ruby | chef
Offline