Is there an easy way to rename all the files within a folder? My
specific situation is that I have a few hundred photos in a folder and I
want to rename them all as a number, starting at 199, so the first photo
would be called 199.jpg, the second 200.jpg, then 201.jpg, and so on.

I'm sure it would be using some kind of a loop while adding 1 each loop
but i wouldn't even know how to start. For now I'll just rename them all
by hand like I've always done. What a pain that is!

TIA,
Jim

Re: Renaming Files by Jim

Jim
Thu May 11 11:36:43 CDT 2006

Jim in Arizona wrote:
> Is there an easy way to rename all the files within a folder? My
> specific situation is that I have a few hundred photos in a folder and I
> want to rename them all as a number, starting at 199, so the first photo
> would be called 199.jpg, the second 200.jpg, then 201.jpg, and so on.
>
> I'm sure it would be using some kind of a loop while adding 1 each loop
> but i wouldn't even know how to start. For now I'll just rename them all
> by hand like I've always done. What a pain that is!
>
> TIA,
> Jim

I tried this but I didn't get very far. I tried manipulating the script
from here:
http://www.microsoft.com/technet/scriptcenter/scripts/storage/files/stfivb30.mspx

I didn't have much luck. Here's what I tried:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'c:\\photos1\*.jpg'")

Dim i
i = 0
For Each objFile in colFiles
i = i+1
errResult = objFile.Rename("c:\photos1\*" & i & ".jpg")
Wscript.Echo errResult
Next

Re: Renaming Files by Carey

Carey
Thu May 11 12:14:23 CDT 2006

Hi, try using fso, something like this. This is rough draft so you'll
need to play with it. Good luck

Dim FilePath
Dim fs, ObjDirectory
Dim TheFiles, File, FDate
Dim oFile

FilePath="set file path"

Set fs = CreateObject("Scripting.FileSystemObject")
Set ObjDirectory = fs.GetFolder(FilePath)
Set TheFiles = objDirectory.Files
Set oFile = fs.GetFile(theFile)

Dim i
i = 0

For Each File in TheFiles
if right(File.Path,3)="jpg" then'Only those with .jpg extention
i = i+1
oFile.Name = FilePath & \" & i & ".jpg"
end if
Next

wscript.Quit

'http://www.sloppycode.net/Reference/FSO/Ref-116.html