Private Sub cmdRenameAll_Click() Dim folderPath As String Dim prefix As String Dim fileName As String Dim oldPath As String Dim newPath As String folderPath = txtPath.Text prefix = txtPrefix.Text ' Ensure the folder path ends with a backslash If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\" ' Target the first file in the directory fileName = Dir(folderPath & "*.*") If fileName = "" Then MsgBox "No files found in the specified directory.", vbExclamation, "Error" Exit Sub End If Do While fileName <> "" ' Avoid renaming folders or re-processing already prefixed files If InStr(fileName, prefix) <> 1 Then oldPath = folderPath & fileName newPath = folderPath & prefix & fileName ' Rename the file natively Name oldPath As newPath End If ' Get the next file fileName = Dir Loop MsgBox "Batch renaming completed successfully!", vbInformation, "Success" End Sub Use code with caution. Rules for Achieving True Portability in VB6
If you are looking for source code to study or modify, you will typically find these categories of projects:
Private Sub cmdRenameAll_Click() Dim folderPath As String Dim prefix As String Dim fileName As String Dim oldPath As String Dim newPath As String folderPath = txtPath.Text prefix = txtPrefix.Text ' Ensure the folder path ends with a backslash If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\" ' Target the first file in the directory fileName = Dir(folderPath & "*.*") If fileName = "" Then MsgBox "No files found in the specified directory.", vbExclamation, "Error" Exit Sub End If Do While fileName <> "" ' Avoid renaming folders or re-processing already prefixed files If InStr(fileName, prefix) <> 1 Then oldPath = folderPath & fileName newPath = folderPath & prefix & fileName ' Rename the file natively Name oldPath As newPath End If ' Get the next file fileName = Dir Loop MsgBox "Batch renaming completed successfully!", vbInformation, "Success" End Sub Use code with caution. Rules for Achieving True Portability in VB6
If you are looking for source code to study or modify, you will typically find these categories of projects: visual basic 60 projects with source code portable