Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Batch Script: Rename Files

Hi All,

I have a folder full of jpg's that I need to rename.

What is the batch script syntax to find a file (by name) and rename it?

e.g.

rename  my_start_file_name_1234.jpg  my_new_file_name.jpg
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
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
Avatar of detox1978

ASKER

I have around 3,000 files that I want to rename.


Ideally i'd like to parse two txt files.

startname.txt and newname.txt



ren  my_start_file_name_1234.jpg  my_new_file_name.jpg

was what i was after.
Maybe a tad shorter/easier code in vbscript...filerename.vbs
Presumably your files will in the format c:\pathtofile\oldfilename.xxx c:\pathtofile\newfilename.xxx?

If not, a few more examples should solidify things...
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
strStartFile = "C:\StartName.txt"
strNewFile = "C:\NewName.txt"
 
Dim objFile1 : Set objFile1 = objFSO.OpenTextFile(strStartFile)
Dim objFile2 : Set objFile2 = objFSO.OpenTextFile(strNewFile)
 
Do While Not objFile1.AtEndOfStream
  strOld = objFile1.ReadLine
  strNew = objFile2.ReadLine
  If objFSO.FileExists (strOld) Then objFSO.MoveFile strOld, strNew
Loop
 
objFile1.Close
objFile2.Close
 
wscript.quit

Open in new window

Ok great.
Glad it worked for you.