Link to home
Start Free TrialLog in
Avatar of Ray Padilla
Ray PadillaFlag for United States of America

asked on

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
Avatar of NVIT
NVIT
Flag of United States of America image

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

Avatar of Ray Padilla

ASKER

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
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

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
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?
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.
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
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.
In your example, I assume the _Forupload starts at c:\_Forupload
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

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>
Under "c:\users\raymond\desktop\_forupload", you have made some subfolders and some do contain the LV1 and/or LV2 subfolder?
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
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
You are not doing this on a test folder as I suggested?
nope, was to much in a hurry!
now I think I have screwed everything up
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.
I ran that and I see nothing where would be the file be?
It should be in the folder where the CMD prompt was opened to.
Open the CMD prompt again.
Is the file there?
Type: DIR hasty.txt <press enter>
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
Would you like me to look at the hasty.txt file?
...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.
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
I ownloaded a free app that did this for me in about 15 min.
Thanks for your effort.