Batch Rename files in a folder

have a folder containing 50 JPEG Images & I am trying to rename in Batch using folder name & Also by adding __-1 at the end of each JPEG images

Wire-Alum_
________________________
URD-350-350-4-0-WESLEYAN
URD-AL-1350-HUNTER-1000R
Expected Result:

Wire-Alum_
_______________
Wire-Alum_URD-350-350-4-0-WESLEYAN__-1
Wire-Alum_URD-AL-1350-HUNTER-1000R__-1
Larry oklaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael LinkInfrastructure EngineerCommented:
Please see a guide here for 4 different ways this can be completed.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Do they have any extension (JPG, JPEG)?  And you want to rename all files in this folder?


»bp
0
oBdACommented:
Powershell; adjust the filter, if required.
$Source = 'C:\Temp\Wire-Alum'
Get-ChildItem -Path $Source -Filter *.* -File |
	ForEach-Object {Rename-Item -Path $_.FullName -NewName "$([IO.Path]::GetFileName($Source))_$($_.BaseName)__-1$($_.Extension)"}

Open in new window

0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Bill PrewIT / Software Engineering ConsultantCommented:
You can do this with just a DOS command if you want, change into the folder where the files are, and then do:

for %A in (*.*) do @ren %A Wire-Alum_%~nA__-1%~xA

Open in new window


»bp
0
Larry oklaAuthor Commented:
@Bill Prew JPG
0
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, then adjust to:

for %A in (*.jpg) do @ren %A Wire-Alum_%~nA__-1%~xA

Open in new window


»bp
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul SauvéRetiredCommented:
if you want to use Powershell, here is an explanation on how to rename by adding the folder name as prefix to the files in that directory: Rename multiple files in a folder, add a prefix (WIndows)
Goto folder with desired files: e.g. cd "C:\house chores" Notice: address must incorporate quotes "" if there are spaces involved.
...
don't forget to TEST FIRST by making copies your folder until you get the results you want...
0
Larry oklaAuthor Commented:
@Bill Prew

Thanks for your help, it worked just like i want it
0
Bill PrewIT / Software Engineering ConsultantCommented:
Great!


»bp
1
sarabandeCommented:
to add to Bill's solution:

in a batch file you would do

@echo off
REM c:\temp\rename_jpg_to_wire_alum.bat
for /f "delims=" %%A in ('dir /b *.jpg') do ren %%A Wire-Alum_%%~nA__-1.jpg

Open in new window


then navigate to the folder _wire_alum and type

c:\temp\rename_jpg_to_wire_alum

Open in new window


you also could enhance the batch file by passing the folder and the prefix as parameters:

@echo off
REM c:\temp\rename_jpg.bat <path_to_folder> <prefix>
for /f "delims=" %%A in ('dir /b %1\*.jpg') do ren "%1\%%A" %2%%~nA__-1.jpg

Open in new window


then you could call the batch from any folder by

c:\temp\rename_jpg "c:\myuser\documents\_wire_alum"  _Wire_Alum

Open in new window

Sara
1
EirmanChief Operations ManagerCommented:
You will always come up with situations where you need to do complicated renaming.
Instead of writing a script each time, use flash renamer - the best renaming program on earth.
demoYou would simply use  <Parent> <Name>__-1 to  rename your jpg files (except my folder is called ALLDATA).
This is using General mode - Advanced modes with scripting are available.

The result is visible in the live preview column - when you are happy with the preview, press Rename
There is even an undo function.
1
EirmanChief Operations ManagerCommented:
This seems like a fair distribution of points based on the OP's comments & endorsements
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.