Solved Batch Script To Rename Subfolders in multiple Subfolders

October 12, 2017 at 04:33:10
Specs: Windows 10
Hi There!

Hoping to get some help with creating a batch script to rename multiple subfolders in multiple subfolders.

For example:

I have a folder saved in my C Drive called "Test". In that folder, I have 4 subfolders - Bill, Bob, Joe & Sue. In each of those 4 subfolders, I have 3 subfolders - Test 1, Test 2 & Test 3.

I'm hoping for my script to rename all of the "Test 2" subfolders to "Correct Folder".

I'm assuming I will have to use a loop, the REN command and a wildcard...but, I'm pretty much stuck there...

Can anyone assist me with preparing the script - and explain the reasoning for how you came up with it (so I can learn what I was missing).

Thanks in advance for your help!


See More: Batch Script To Rename Subfolders in multiple Subfolders

Reply ↓  Report •

#1
October 12, 2017 at 06:31:31
✔ Best Answer
You can't rename directories; you can only move their contents to a new directory. CMD emulates certain DOS behavior, and that restriction has been in place as long as DOS has had directories. (REN came first, then directories, then MOVE.)

If you're going to run this script from the "Test" folder, (which is the same restriction as the last script,) you can probably use this (untested):

FOR /D %%a IN (*) DO MOVE  "%%a\Test 2" "%%a\Correct Folder"

How To Ask Questions The Smart Way


Reply ↓  Report •

#2
October 12, 2017 at 10:45:01
Dunno win10 but REN has worked since about DOS 3.10
and still does in XP.

::====== script starts here ===============
::
:: JW.bat 2017-10-13 0:01:08.51
@echo off & setLocal enableDELAYedeXpansioN

md test\Bill\Test1
md test\Bill\Test2
md test\Bill\Test3

md test\Bob\Test1
md test\Bob\Test2
md test\Bob\Test3

md test\Joe\Test1
md test\Joe\Test2
md test\Joe\Test3

md test\Sue\Test1
md test\Sue\Test2
md test\Sue\Test3

tree

:main
for %%a in (Bill Bob Joe Sue) do (
pushd test\%%a
ren Test2 "Correct Folder"
popd
)
tree
goto :eof
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#3
October 12, 2017 at 13:06:32
I'm pretty sure REN didn't work back in the DOS days. Otherwise, it'd be a strange lesson to learn, but I'm glad to know it's a quirk I can unlearn.

How To Ask Questions The Smart Way


Reply ↓  Report •

Related Solutions

#4
October 12, 2017 at 21:54:47
Hi R2,

You were right and I was wrong. I've been using NTVDM so long I forgot about DOS REN.
"DOS Power Tools" from Ziff-Davis had RENDIR; you can guess why.

2017-10-13 11:51:22.20 GMT +7

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#5
October 13, 2017 at 18:55:10
@ Razor2.3

Thank you, again, so much for your help! That worked perfectly! I really appreciate it!


@ Mechanix2Go

Thanks very much for your reply as well!


Reply ↓  Report •

Ask Question