Link to home
Start Free TrialLog in
Avatar of GIL BAUMGARTEN
GIL BAUMGARTEN

asked on

Excel VBA: Rename Files in folder

Hello,

I have some images in a folder but these images have the ".jpg" included in the name of the image. I need an Excel VBA routine to remove the ".jpg" from the name of the image.

Here is an example.
Old file name: "123image.jpg"
Old file name: "456image.jpg"

New file name: "123image"
New file name: "456image"

Thanks.
Avatar of Ardhendu Sarangi
Ardhendu Sarangi
Flag of United States of America image

hi

you can do this with other tools. you don't need excel for this.

try irfanview - there is a batch option for renaming files which is quite easy.

- Ardhendu

pari123 is Right, you don't need Excel for this.

you can do this by simply using DOS command.

Open command prompt, navigate to the folder that contains your images and run this command

ren *.jpg *.

Or copy attached batch file (rename it to Remove_jpg.bat) to that folder and run it.
  Remove-jpg.bat.txt

If you actually need this in excel, please post here and we will post the code.
Avatar of GIL BAUMGARTEN
GIL BAUMGARTEN

ASKER

Magadu: the command prompt says"The syntax of this command is incorrect."
Probaly because of spaces.


ren *.jps .*

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Magadu
Magadu
Flag of Canada 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
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\FSO\"
objFSO.MoveFile strFolder &"123image.jpg", strFolder &"123image"
Even easier without FSO:

FileName = "C:\MyFile.txt"
NewFileName = "C:\Text1.txt"
Name FileName As NewFileName