Option Explicit
Private Function RenameFiles(FolderName As String, fileType As String) As Long
On Error GoTo RenameErr
Dim FileName As String
Dim CurrentID As Long
RenameFiles = 0
If (Right(FolderName, 1) <> "\") Then FolderName = FolderName & "\"
FileName = Dir(FolderName & fileType)
CurrentID = 0
Do While FileName <> ""
Name FolderName & FileName As FolderName & Format(CurrentID & "0000") & Right(fileType, 4)
CurrentID = CurrentID + 1
RenameFiles = RenameFiles + 1 ' return number of renamed files
FileName = Dir ' get next file
Loop
Exit Function
RenameErr:
MsgBox "Error renaming files. " & Err.Number & " : " & Err.Description
On Error GoTo 0
End Function
Private Sub Command1_Click()
RenameFiles "c:\FileFolder", "*.jpg"
End Sub
Main Topics
Browse All Topics





by: supunrPosted on 2003-08-31 at 17:01:56ID: 9258823
use the name statement....let me give you the code to rename sequentially....