Ray Padilla
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
ASKER
Not sure what that is supposed to do but the directory structure is as follows:
_Forupload\ProductName\Ima ges\Produc tName\LV1
I need that to look like this when I get done
_ForUpLoad\ProductName\Ima ges\LV1-or g
Keep in mind the Lv1 is a folder
_Forupload\ProductName\Ima
I need that to look like this when I get done
_ForUpLoad\ProductName\Ima
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
)
ASKER
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\Ima ges\Produc tName
changes to _ForUpLoad\ProductName\Ima ges
The second ProductName is removed. That was not is your original request.
Is that a typo?
Change c:\source to c:\_Forupload
You show _Forupload\ProductName\Ima
changes to _ForUpLoad\ProductName\Ima
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.
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.
ASKER
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.
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
)
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
)
ASKER
my results:
C:\Users\Raymond\Desktop>r enamefolde r.bat
C:\Users\Raymond\Desktop>d ir "c:\users\raymond\desktop\ _forupload \lv*" /s/b /ad
1>"C:\Users\Raymond\AppDat a\Local\Te mp\lv.txt"
The system cannot find the file specified.
C:\Users\Raymond\Desktop>f or /F %a in (C:\Users\Raymond\AppData\ Local\Temp \lv.tx
t) do (ECHO ren "%a" %~na-Org )
C:\Users\Raymond\Desktop>
C:\Users\Raymond\Desktop>r
C:\Users\Raymond\Desktop>d
1>"C:\Users\Raymond\AppDat
The system cannot find the file specified.
C:\Users\Raymond\Desktop>f
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?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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-H ydrojet-SS -15Deg-3-5 -Threaded- Nozz-17-06 47_HTML\Im ages\1-8In ch-Hydroje t-SS-15Deg -3-5-Threa ded-Nozz-1 7-0647_HTM L
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.
C:\Users\Raymond\Desktop\_
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?
ASKER
nope, was to much in a hurry!
now I think I have screwed everything up
now I think I have screwed everything up
Yikes.
If you still need help...
In the CMD prompt, type:
Upload Hasty.txt and I'll take a look.
If you still need help...
In the CMD prompt, type:
dir /s /b "C:\Users\Raymond\Desktop\__ForUpload\lv*" > Hasty.txt
Upload Hasty.txt and I'll take a look.
ASKER
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?
Open the CMD prompt again.
Is the file there?
Type: DIR hasty.txt <press enter>
ASKER
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 -orgThere are 2 things happening here.
Also, this is different from your original request.
I need a clearer explanation.
ASKER
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
ASKER
I ownloaded a free app that did this for me in about 15 min.
ASKER
Thanks for your effort.
Open in new window