Discussion:
How do I rename files based on current name...
(too old to reply)
My Full Name
2003-08-13 22:42:51 UTC
Permalink
Hello... kind of new to this WSH thing...
I have many files that my digital camera likes to label gibberish names
(Image001.jpg, etc.). What I'd like to do is, after I unload them from the
flash card to my computer, run a script that says For all .jpg files in
current folder, cycle through the names and rename the 'Image' part of the
original file name to something that I can understand ('lake-001',
'vacation2003-001', etc.).
I've been reading through the group for a little bit now and have tried the
renaming a particular folder or file to a specified new name, but how can
this be done automatically?
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.GetFile("C:\tester\test.txt").Name = "ItSeemsToWork.bat"

Is there a way to read the dir listing into an array, then edit that array,
then cycle back through the files renaming them to the new names? there
must be... I just don't know how.
Joerg
2003-08-14 08:20:05 UTC
Permalink
Post by My Full Name
I've been reading through the group for a little bit now and have tried the
renaming a particular folder or file to a specified new name, but how can
this be done automatically?
Hi,

i wrote a script to change file names of a folder. Hope this helps.

Sincerly,

Joerg

'***********
Option Explicit

Const path = "C:\city"'the folder containing your files

Dim Text, Titel, i, j, fil
Dim fso, fo, fi, wsh
Dim count

Set fso = CreateObject("Scripting.FileSystemObject")

Set fo = fso.GetFolder( path)

Set fi = fo.Files '
count = 0

' here can you modify all files
For Each i In fi
count = count + 1
i.Name = "newName" & count &".jpg"
Next

MsgBox Text, vbOkonly + vbInformation, Titel

WScript.Quit
'*** End
Bill Wallace
2003-08-14 15:37:10 UTC
Permalink
Here is another based on the original name:

Dim fso, fldr, fyle

Sub renameFiles(folderspec, sName)

Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(folderspec)

For Each fyle In fldr.files
Dim fName, oldName, newName
fName = fyle.Name
If LCase(Right(fName, 3)) ="jpg" Then

oldName = folderSpec & fName
'Assuming you want to keep the last 3 characters
newName = folderspec & sName & mid(fName, Len(fName)-6, 3) & ".jpg"

msgBox oldName & vbCrLf & newName
'fso.MoveFile oldName, newName

End If
Next

End Sub

renameFiles "C:\folderPath", "newName"


gl,
Bill Wallace
Post by Joerg
Post by My Full Name
I've been reading through the group for a little bit now and have tried the
renaming a particular folder or file to a specified new name, but how can
this be done automatically?
Hi,
i wrote a script to change file names of a folder. Hope this helps.
Sincerly,
Joerg
'***********
Option Explicit
Const path = "C:\city"'the folder containing your files
Dim Text, Titel, i, j, fil
Dim fso, fo, fi, wsh
Dim count
Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.GetFolder( path)
Set fi = fo.Files '
count = 0
' here can you modify all files
For Each i In fi
count = count + 1
i.Name = "newName" & count &".jpg"
Next
MsgBox Text, vbOkonly + vbInformation, Titel
WScript.Quit
'*** End
Continue reading on narkive:
Loading...