Simple rename loop?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Andrius
Posts: 37
Joined: 26 Jun 2012 15:15

Simple rename loop?

#1 Post by Andrius » 26 Jul 2012 16:36

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.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Simple rename loop?

#2 Post by Squashman » 26 Jul 2012 16:49

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"

Andrius
Posts: 37
Joined: 26 Jun 2012 15:15

Re: Simple rename loop?

#3 Post by Andrius » 26 Jul 2012 16:53

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

Post Reply