Page 1 of 1

Simple rename loop?

Posted: 26 Jul 2012 16:36
by Andrius
Could someone hook me up with a script that will go through a folder substructure and rename a specific folder and continue through until there are no other folders to process? Basically search for folder "a" and rename to "b"

Example of what i need done

Code: Select all

BEFORE:
c:\Root_Folder\script.bat
c:\Root_Folder\Folder1\
c:\Root_Folder\Folder1\random_folder1
c:\Root_Folder\Folder1\wrongname_folder2
c:\Root_Folder\Folder1\random_folder3
c:\Root_Folder\Folder1\random_folder4

AFTER:
c:\Root_Folder\script.bat
c:\Root_Folder\Folder1\
c:\Root_Folder\Folder1\random_folder1
c:\Root_Folder\Folder1\correct_folder2
c:\Root_Folder\Folder1\random_folder3
c:\Root_Folder\Folder1\random_folder4


in a loop so that it can process a ton of these.

Re: Simple rename loop?

Posted: 26 Jul 2012 16:49
by Squashman
Here is your fish.

Code: Select all

@echo off
FOR /F "delims=" %%G in ('dir /ad /b /s ^|findstr /E /I /C:"wrongfolder"') do rename "%%~G" "RightFolder"

Re: Simple rename loop?

Posted: 26 Jul 2012 16:53
by Andrius
Squashman wrote:Here is your fish.

Code: Select all

@echo off
FOR /F "delims=" %%G in ('dir /ad /b /s ^|findstr /E /I /C:"wrongfolder"') do rename "%%~G" "RightFolder"


Thanks for teh fish