How do I rename a folder using wildcards?

February 25, 2010 at 13:03:48
Specs: Windows XP, 4gigs
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?


See More: How do I rename a folder using wildcards?

Report •


#1
February 26, 2010 at 03:53:04
What you want to achieve is indeed possible, but using the following statement

for /D %%j in (C:\FolderA\*) do move %%j %%~dpj\NewName

according to your sample structure (and assuming obviously there is just ONE folder in FolderA).

To issue the command at prompt replace %% with just ONE %.


Report •

#2
February 26, 2010 at 08:50:46
Thanks IVO. I tried your script and I get an error *listed below*.
Note the path isn't really "C:\FolderA\*" I just used that in the demonstration to illustrate what I was trying to do.

As my goal is to rename the Firefox profile folder to "default", the real path I'm using is:
C:\Documents and Settings\Default\Application Data\Mozilla\Firefox\Profiles

I tested this (your) script on my virtual sandbox XP image:
for /D %%j in (c:\Documents and Settings\Default\Application Data\Mozilla\Firefox\Profiles\*) do move %%j %%~dpj\default
pause
(added the pause so I could see the results)

I get the following error when its run:
C:\WINDOWS\system32>for / %j in (c:\Documents and Settings\Default\Application D
ata\Mozilla\Firefox\Profiles\*) do move %j %~dpj\default

C:\WINDOWS\system32>move c:\Documents c:\\default
The system cannot find the file specified.

C:\WINDOWS\system32>move and C:\WINDOWS\system32\\default
The system cannot find the file specified.

C:\WINDOWS\system32>move Settings\Default\Application C:\WINDOWS\system32\Settin
gs\Default\\default
The system cannot find the path specified.

C:\WINDOWS\system32>pause


Report •

#3
February 26, 2010 at 09:02:06
Oh ... the old whitespace issue. Need some quotes somewhere ...

Report •

Related Solutions

#4
February 26, 2010 at 09:05:21
I don't understand what you are trying to do

Are you moving all files: C:\folderA\folderB\*
into directory : C:\folderA

?


Report •

#5
February 26, 2010 at 12:29:41
TVC: I think I explained my situation pretty well above.
Specifically my goal is to automate renaming the Firefox profile folder from a randomly generated alphanumeric set of characters to "default".

I have however found a solution (thanks TheOutcaste). The following script gets the job done nicely:
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


Report •

#6
February 26, 2010 at 12:34:55
This solves the embedded spaces issue

@echo off
pushd C:\Documents and Settings\Default\Application Data\Mozilla\Firefox\Profiles
for /D %%j in (*) do move "%%j" "%%~dpj\NewName"
popd


Report •

#7
February 27, 2010 at 04:44:28
OK, I understand, you want to rename the Firefox profile generated directory name into a fixed name ...

Yeah, it can be done ;)


Report •


Ask Question