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?
 
Bill PrewCommented:
Okay, then adjust to:

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

Open in new window


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


»bp
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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
 
Bill PrewCommented:
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
 
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 PrewCommented:
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
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.