Can someone show me how I'd rename files in a folder.

I have a folder with 92 jpg images in it all named something like
S0001234.jpg. I want to rename them all 1.jpg, 2.jpg, 3.jpg and so on. I
also want to name everything in another folder 1t.jpg, 2t.jpg, 3t.jpg
and so on.

I know this would be a loop somehow but, well, how?

My beginners VBScript/WSH book is at home otherwise I'd try to get
started on it then post what i've got here.

TIA,
Jim

Re: Renaming files in folder by Ayush

Ayush
Wed May 16 14:15:35 CDT 2007

[Jim in Arizona]s message :
> Can someone show me how I'd rename files in a folder.

> I have a folder with 92 jpg images in it all named something like
> S0001234.jpg. I want to rename them all 1.jpg, 2.jpg, 3.jpg and so on.


folderPath="C:\Documents and settings\Ayush\Desktop\ccs"
extension="jpg"

Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr= fs.GetFolder(folderPath)

For Each File in fldr.Files
fileExtension=fs.GetExtensionName(File.Name)
if fileExtension=extension Then
Count=Count+1
File.Name=Count & "." & fileExtension
EnD if
Next

> I
> also want to name everything in another folder 1t.jpg, 2t.jpg, 3t.jpg
> and so on.

Change the File.Name ... line to:
File.Name=Count & "t." & fileExtension

Good Luck, Ayush.
--
Script Center-Script Repository : http://snipurl.com/Script_Repository

Re: Renaming files in folder by Jim

Jim
Wed May 16 16:15:16 CDT 2007

Ayush wrote:
> [Jim in Arizona]s message :
>> Can someone show me how I'd rename files in a folder.
>
>> I have a folder with 92 jpg images in it all named something like
>> S0001234.jpg. I want to rename them all 1.jpg, 2.jpg, 3.jpg and so on.
>
>
> folderPath="C:\Documents and settings\Ayush\Desktop\ccs"
> extension="jpg"
>
> Set fs = CreateObject("Scripting.FileSystemObject")
> Set fldr= fs.GetFolder(folderPath)
>
> For Each File in fldr.Files
> fileExtension=fs.GetExtensionName(File.Name)
> if fileExtension=extension Then
> Count=Count+1
> File.Name=Count & "." & fileExtension
> EnD if
> Next
>
> > I
> > also want to name everything in another folder 1t.jpg, 2t.jpg, 3t.jpg
> > and so on.
>
> Change the File.Name ... line to:
> File.Name=Count & "t." & fileExtension
>
> Good Luck, Ayush.

Thanks a lot Ayush!

I also was able to do it in vb.net with this (console app)

Sub Main()

Dim i As Int32 = 1
Dim totalfiles As Int16 =
IO.Directory.GetFiles("c:\newphotos").Length - 1
Dim file As String
For Each file In IO.Directory.GetFiles("c:\newphotos")
IO.File.Move(file, "c:\testing\" & i & ".jpg")
i = i + 1
Next

End Sub

But, I still wanted to know how to script it too! :)

Thanks Again.

Jim