We help IT Professionals succeed at work.

Excel VBA: Rename Files in folder

dadgumit
dadgumit asked
on
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.
Comment
Watch Question

Ardhendu SarangiSr. Project Manager

Commented:
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

Commented:
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.

Author

Commented:
Magadu: the command prompt says"The syntax of this command is incorrect."

Commented:
Probaly because of spaces.


ren *.jps .*

Open in new window

Commented:
Spelled it wrong. Should be JPG not JPS  and shoudl be *. not .*

Copy and paste the code. It shoudl work.




ren *.jpg *.

Open in new window

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