Solved Batch renaming a set of folders

February 20, 2013 at 13:42:49
Specs: Windows XP
I 'm using following batch command from the command line for renaming a set of folders in a directory like C:\test with 15 folders, but it renames some of them multiple times.

for /d %D in ("Workspace\*") do ren "%D" "%~nxD_myName"

Any idea would be appreciated.

See More: Batch renaming a set of folders

Report •

February 21, 2013 at 05:46:49
✔ Best Answer
for /F "delims=" %D in ('dir /B /AD "Workspace"') do move "%D" "%~nxD_myName"

Report •

February 23, 2013 at 16:06:51
Thank you for your quick answer IVO...

I tried your answer it worked perfectly, but with a little problem,
I have 3 folders that I had renamed them like below to pass them to
my code as its arguments, these folders are renamed like below:

[Alt + 10]_10
[Alt + 11]_11
[Alt + 12]_12

From Alt I mean the Alt key on keyboard plus character codes from
10 to 12 without of course brackets. I know it's somewhat bizarre
to have these characters as a folder name but I wanted to apply the
worst. After using your answer the message of CMD for these folders
was like:

D:\Test>move "_10" "_10_MyName"
The system cannot find the file specified.

D:\Test>move "♀_12" "♀_12_MyName"
The filename, directory name, or volume label syntax is incorrect.

D:\Test>move "♂_11" "♂_11_MyName"
The filename, directory name, or volume label syntax is incorrect.

<Test> is the folder where these folders reside.
Thank you once more

Report •

February 24, 2013 at 02:58:54
Sorry, what you report is not a failure of my solution but the nominal behavior of the cmd interpreter, i.e. the characters 00-31 (00h-1Fh) are interpreted as control codes and not part of a folder/filename since multi keystrokes are not recognized. This happens because cmd (and batch scripts) use the basic ASCII characters table.

Report •

Related Solutions

February 24, 2013 at 14:01:47
IVO, I got the point, useful and complete.
Thank you

Report •

Ask Question