# Batch directory (folder) rename



## spackler (Mar 9, 1999)

Any batch file guru's know of a way to add a short string of text to all directories under a main directory within Windows?

As an illustration I would like to rename all directories (folders) under
c:\documents and settings\profilename\main\
c:\documents and settings\profilename\main\jones
c:\documents and settings\profilename\main\johnson
c:\documents and settings\profilename\main\kohl
c:\documents and settings\profilename\main\larson
c:\documents and settings\profilename\main\olson

to
c:\documents and settings\profilename\main\jones#HC
c:\documents and settings\profilename\main\johnson#HC
c:\documents and settings\profilename\main\kohl#HC
c:\documents and settings\profilename\main\larson#HC
c:\documents and settings\profilename\main\olson#HC

Thanks for any suggestions!


----------



## ghostdog74 (Dec 7, 2005)

```
@echo off
for /D  %%i in (c:\somdir\*) do ( 
	echo %%i %%i#HC	
	)
```
substitute echo with move or ren command....


----------



## spackler (Mar 9, 1999)

Thanks ghostdog I'm getting the following error. 

C:\>for / %i in (c:\test\*) do (ren %i %i#HC )

C:\>(ren c:\test\Anderson#1 c:\test\Anderson#1#HC )
The syntax of the command is incorrect.

The directories (folders) that I want to rename are located under c:\test

My code = 


for /D %%i in (c:\test\*) do ( 
ren %%i %%i#HC	
)
pause

Any idea why I'm getting that error?

Thanks.


----------



## spackler (Mar 9, 1999)

Anyone know if/how this could be done?


----------



## dtech10 (Jan 31, 2003)

@echo off
dir e:\win98 /ad /b > Dirs.txt
for /f %%i in (Dirs.txt) do ( 
ren e:\Win98\%%i %%i#HC
)


----------



## dtech10 (Jan 31, 2003)

Don't forget to change the directory name 
here it's e:\Win98 
@echo off
dir e:\win98 /ad /b > Dirs.txt
for /f %%i in (Dirs.txt) do ( 
ren e:\Win98\%%i %%i#HC
)


----------



## spackler (Mar 9, 1999)

thanks dtech - worked great!

For my understanding - it has to list them in the text file and then make the change or is the text file just there for a log of the change?


----------



## dtech10 (Jan 31, 2003)

Hi Spackler
The text file is just the list of directories the exist in that folder. and should be deleted after use.
If used without the text file with something like....
for /f %%a in ('dir e:\win98 /ad /b') do ren e:\win98\%%a %%a#HC
The for command would use all the existing directory names and also the ones that have been changed, which would eventuly come up with a directory that not longer existed or rename some again to File#HC#HC.
Hope this helps.


----------

