Script for renaming subfolders with same name

Hey Experts, I have a Folder with hundreds of folders each folder has subfolders the last level of folders are named Lv1 and LV2, I need to rename those folders ONLY to Lv1-org and Lv2-org
padillrrProject CoordinatorAsked:
Who is Participating?
 
NVITCommented:
This version makes a log file %temp%\RenLV.txt

@echo off
set LogFN=%temp%\RenLV.txt
if exist "%LogFN%" del /q "%LogFN%"

dir "C:\local\test\_Forupload\lv*" /s/b /ad >"%temp%\lv.txt"
for /f %%a in (%temp%\lv.txt) do (
  echo %date% %time% "%%a" %%~na-Org
  echo %date% %time% "%%a" %%~na-Org >>"%LogFN%"
  ren "%%a" %%~na-Org
)

Open in new window


It works here on Windows 7.
See attachments

With the ECHO version...
RenLV.bat

dir "C:\local\test\_Forupload\lv*" /s/b /ad  1>"C:\Users\chris\AppData\
Local\Temp\lv.txt"

for /F %a in (C:\Users\chris\AppData\Local\Temp\lv.txt) do (echo ren "%a" %~na-Org )
(echo ren "C:\local\test\_Forupload\ProductName1\Images\ProductName\lv1" lv1-Org )
ren "C:\local\test\_Forupload\ProductName1\Images\ProductName\lv1" lv1-Org
(echo ren "C:\local\test\_Forupload\ProductName1\Images\ProductName\lv2" lv2-Org )
ren "C:\local\test\_Forupload\ProductName1\Images\ProductName\lv2" lv2-Org
(echo ren "C:\local\test\_Forupload\ProductName2\Images\ProductName\lv1" lv1-Org )
ren "C:\local\test\_Forupload\ProductName2\Images\ProductName\lv1" lv1-Org
(echo ren "C:\local\test\_Forupload\ProductName2\Images\ProductName\lv2" lv2-Org )
ren "C:\local\test\_Forupload\ProductName2\Images\ProductName\lv2" lv2-Org

Open in new window

---
With the real version (ECHO removed)...
RenLV.bat

dir "C:\local\test\_Forupload\lv*" /s/b /ad  1>"C:\Users\chris\AppData\Local\Temp\lv.txt"

for /F %a in (C:\Users\chris\AppData\Local\Temp\lv.txt) do (ren "%a" %~na-Org )
(ren "C:\local\test\_Forupload\ProductName1\Images\ProductName\lv1" lv1-Org )
(ren "C:\local\test\_Forupload\ProductName1\Images\ProductName\lv2" lv2-Org )
(ren "C:\local\test\_Forupload\ProductName2\Images\ProductName\lv1" lv1-Org )
(ren "C:\local\test\_Forupload\ProductName2\Images\ProductName\lv2" lv2-Org )

Open in new window

RenLV1.png
RenLV2.png
0
 
NVITCommented:
Revised.

dir "c:\source\lv*" /s/b /ad >"%temp%\lv.txt"
for /f %%a in (%temp%\lv.txt) do (
  echo ren "%%a" %%~na-Org
)

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
Not sure what that is supposed to do but the directory structure is as follows:

_Forupload\ProductName\Images\ProductName\LV1

I need that to look like this when I get done

_ForUpLoad\ProductName\Images\LV1-org

Keep in mind the Lv1 is a folder
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
NVITCommented:
To run it for real, removed the ECHO.

dir "c:\source\lv*" /s/b /ad >"%temp%\lv.txt"
for /f %%a in (%temp%\lv.txt) do (
  ECHO ren "%%a" %%~na-Org
)

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
There are 2 Folders in the images folder Lv1 and Lv2 they both need to keep the name and just append the -org to the end of the folder name
0
 
NVITCommented:
Yes. That's what it will do.
Change c:\source to c:\_Forupload

You show _Forupload\ProductName\Images\ProductName
changes to _ForUpLoad\ProductName\Images

The second ProductName is removed. That was not is your original request.
Is that a typo?
0
 
NVITCommented:
Open Notepad or another editor.
Copy the code to it
Save it to a file of your choice, e.g. c:\renameLV.bat
Open a CMD prompt
Type: c:\renameLV.bat

You'll see the results echo to the console.

If you are satisfied... to run it for real, remove the ECHO then save and run it again.
0
 
padillrrProject CoordinatorAuthor Commented:
yes that is a typo  The directory structure should not change I just need to find any folder within these folders named Lv1 and name them to Lv1-org same thing with the Lv2 folder it also needs to be renamed to Lv2-org
0
 
NVITCommented:
If you are unsure, test it on a few folders first.
Make a different folder structure and put some subfolders in it, similar to the real one.
0
 
NVITCommented:
In your example, I assume the _Forupload starts at c:\_Forupload
0
 
NVITCommented:
If you do a test, don't forget to adjust the .BAT file path to match your test folder. E.g. if you make a test called c:\test
dir "c:\test\lv*" /s/b /ad >"%temp%\lv.txt"
for /f %%a in (%temp%\lv.txt) do (
  ECHO ren "%%a" %%~na-Org
)

Open in new window

In the real one...
dir "c:\_Forupload\lv*" /s/b /ad >"%temp%\lv.txt"
for /f %%a in (%temp%\lv.txt) do (
  ECHO ren "%%a" %%~na-Org
)

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
my results:


C:\Users\Raymond\Desktop>renamefolder.bat

C:\Users\Raymond\Desktop>dir "c:\users\raymond\desktop\_forupload\lv*" /s/b /ad
 1>"C:\Users\Raymond\AppData\Local\Temp\lv.txt"
The system cannot find the file specified.

C:\Users\Raymond\Desktop>for /F %a in (C:\Users\Raymond\AppData\Local\Temp\lv.tx
t) do (ECHO ren "%a" %~na-Org )

C:\Users\Raymond\Desktop>
0
 
NVITCommented:
Under "c:\users\raymond\desktop\_forupload", you have made some subfolders and some do contain the LV1 and/or LV2 subfolder?
0
 
padillrrProject CoordinatorAuthor Commented:
in the _ForUpLoad there are subfolders in subfolders as per my previous comment I just need to find the LV1 and rename it to LV1-org
0
 
padillrrProject CoordinatorAuthor Commented:
OK do I did something stupid and really screwed up. Now I have a bunch of folders named LV1 (1)  These folders have to be LV1 arggggghhh!

C:\Users\Raymond\Desktop\__ForUpload\1-8Inch-Hydrojet-SS-15Deg-3-5-Threaded-Nozz-17-0647_HTML\Images\1-8Inch-Hydrojet-SS-15Deg-3-5-Threaded-Nozz-17-0647_HTML

This is the file structure with each product name being different of course but under that last folder there are 2 folders LV1 (1) and Lv2 I need to revert that Lv (1) back to Lv1

I'm sorry I am in a rush and somehow just screwed up all these folders.
0
 
NVITCommented:
You are not doing this on a test folder as I suggested?
0
 
padillrrProject CoordinatorAuthor Commented:
nope, was to much in a hurry!
now I think I have screwed everything up
0
 
NVITCommented:
Yikes.

If you still need help...

In the CMD prompt, type:
dir /s /b "C:\Users\Raymond\Desktop\__ForUpload\lv*" > Hasty.txt

Open in new window


Upload Hasty.txt and I'll take a look.
0
 
padillrrProject CoordinatorAuthor Commented:
I ran that and I see nothing where would be the file be?
0
 
NVITCommented:
It should be in the folder where the CMD prompt was opened to.
Open the CMD prompt again.
Is the file there?
0
 
NVITCommented:
Type: DIR hasty.txt <press enter>
0
 
padillrrProject CoordinatorAuthor Commented:
I would like to remove anything after Lv1 & Lv2  then on a VERY similar folder I need to add to the Folders Lv1 & Lv2  -org
0
 
NVITCommented:
Would you like me to look at the hasty.txt file?
0
 
NVITCommented:
...would like to remove anything after Lv1 & Lv2  then on a VERY similar folder I need to add to the Folders Lv1 & Lv2  -org
There are 2 things happening here.
Also, this is different from your original request.

I need a clearer explanation.
0
 
padillrrProject CoordinatorAuthor Commented:
Sorry it changed once I screwed things up.  Best way to explain it is I need to copy over a bunch of folders but I DO NOT want to copy over the LV1 and LV2 folders those need to be skipped that was why I needed to rename the original folders before I copied over the other files, but I accidentally renamed the folders of the files I did NOT need to name. So from my Productparts folder I will copy everything into my Forupload folder EXCEPT the LV1 and LV2 folders those need to remain as they are in the uploadfolder.  Those folders contain images I have watermarked and need to get up to our site
0
 
padillrrProject CoordinatorAuthor Commented:
I ownloaded a free app that did this for me in about 15 min.
0
 
padillrrProject CoordinatorAuthor Commented:
Thanks for your effort.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.