# Solved: How do I rename a folder using wildcards in xp dos?



## ryeookin (May 3, 2007)

What I'm trying to do: 
From a command line in XP I'm trying to rename a folder within a folder using a wildcard (I need to automate this via a batch file and the file name varies on every pc).

In using the example: c:\folderA\folderB
I tried to change folderB's name via:
rename c:\folderA\* newname
move c:\folderA\* newname

In either case it only renames the files in folderA not folderB itself even though the wild card was used.

Anyone know how this can be accomplished?


----------



## TheOutcaste (Aug 8, 2007)

```
PushD C:\FolderA
For /F "Tokens=*" %%I In ('Dir /AD /B') Do Ren %%I Newname
PopD
```
This will rename the first folder in *FolderA*. If there is more than one folder in *FolderA*, they will generate this error and won't be renamed:
A duplicate file name exists, or the file
cannot be found.
You can suppress the error message by adding* 2>Nul* after *Newname*

Jerry


----------



## ryeookin (May 3, 2007)

Thanks TheOutcaste!

I used your script on my virtual XP sandbox image and it works like a champ! My goal which this script makes possible is to automate renaming the Firefox profile folder to "default".

I used your script as such:
PushD c:\Documents and Settings\Default\Application Data\Mozilla\Firefox\Profiles\
For /F "Tokens=*" %%I In ('Dir /AD /B') Do Ren "%%I" default
PopD
pause

The only minor modification I made was to add quotes in-between %%I as I found if there is a space in the folder name the expression fails.

Thanks again.


----------



## TheOutcaste (Aug 8, 2007)

Me and Quotes, I'm always forgetting them. I always try and test with files and folders with spaces so I catch that, but it slipped by this time.

If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Left of this thread (above the first post) 










Jerry


----------

