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