patriciaxxx
Programmer
I have the following vbscript which works as follows.
Giving that the specified directory contains 72 pics.
It renames them sequencially 01 to 72.
Must begin 01 and not 00
I need to modify it to include the following an optional mixed character prefix. The problem is when I add one that begins with a letter lets say I use “p12ax_” it adds it but the numbering begins 00 so I get p12ax_00 to p12ax_71 but I need p12ax_01 to p12ax_72.
Option Explicit
Dim strPath
Dim FSO
Dim FLD
Dim fil
Dim strOldName
Dim strNewName
Dim strLeadingZero
Dim intFileParts
Dim strFileParts
'Define file path.
strPath = "C:\Documents and Settings\Rename Pictures for Web Use\pic\"
'Create the instance of the FSO.
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set the folder you want to search.
Set FLD = FSO.GetFolder(strPath)
'Loop through each file in the folder.
For Each fil in FLD.Files
'Get complete file name with path.
strOldName = fil.Path
'Build the new file name.
strLeadingZero = "00" 'Maximum files in folder 100.
intFileParts = intFileParts + 1
strFileParts = strLeadingZero & CStr(intFileParts)
strFileParts = Right(strFileParts, Len(strLeadingZero))
strNewName = strPath & strFileParts & Right(strOldName, 4) 'Right function keep file extension.
'Use the MoveFile method to rename the file.
FSO.MoveFile strOldName, strNewName
Next
'Cleanup the objects.
Set FLD = Nothing
Set FSO = Nothing
Giving that the specified directory contains 72 pics.
It renames them sequencially 01 to 72.
Must begin 01 and not 00
I need to modify it to include the following an optional mixed character prefix. The problem is when I add one that begins with a letter lets say I use “p12ax_” it adds it but the numbering begins 00 so I get p12ax_00 to p12ax_71 but I need p12ax_01 to p12ax_72.
Option Explicit
Dim strPath
Dim FSO
Dim FLD
Dim fil
Dim strOldName
Dim strNewName
Dim strLeadingZero
Dim intFileParts
Dim strFileParts
'Define file path.
strPath = "C:\Documents and Settings\Rename Pictures for Web Use\pic\"
'Create the instance of the FSO.
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set the folder you want to search.
Set FLD = FSO.GetFolder(strPath)
'Loop through each file in the folder.
For Each fil in FLD.Files
'Get complete file name with path.
strOldName = fil.Path
'Build the new file name.
strLeadingZero = "00" 'Maximum files in folder 100.
intFileParts = intFileParts + 1
strFileParts = strLeadingZero & CStr(intFileParts)
strFileParts = Right(strFileParts, Len(strLeadingZero))
strNewName = strPath & strFileParts & Right(strOldName, 4) 'Right function keep file extension.
'Use the MoveFile method to rename the file.
FSO.MoveFile strOldName, strNewName
Next
'Cleanup the objects.
Set FLD = Nothing
Set FSO = Nothing