I asked this question here: http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23103040.html
I am currently using this batch script to rename folders within a directory to have the same name as the directory plus the last two digits from the folder to be renamed.
i.e. C:\Test\trial05 will become C:\Test\Test05
But then I realized that some of my folders to be renamed only have single digit numbers (e.g. 1, 2, 3, 4, etc)
is there a way to make this script just add the number from a counter starting at 01 to each renamed folder?
Also is there a way to insert a "_" between name and number in renamed folders (e.g. test_05 instead of test05)?
and I thought the code below worked, but it doesnt.
I get the following error message:
"a duplicate file name exists"
So basically it will only rename the first nine folders name_01 - name_09.
Is there a script that will rename my folder from C:\Test\trial01 will become C:\Test\Test_01? While still taking into considertion that sometimes they might be numbered with a single digit (i.e. C:\Test\trial1 will become C:\Test\Test01)? Or do I need two scripts?
Thank you kindly,
REM The folder containing A, B, C, etc.
for /F "usebackq" %%G in (`dir "%root%" /A:D /B`) do (
for /F "usebackq" %%H in (`dir "%root%\%%G" /A:D /B`) do (
if not "!newdir:~-2,1!"=="0" (set newdir=%%G_0!newdir:~-1!) else (set newdir=%%G_!newdir:~-2!)
ren "%root%\%%G\%%H" "!newdir!"