Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Rename file list


Private Sub  mnuRename_Click()
'On Error GoTo renameerror

Dim temp As String , temp2 As String
Dim i As Long , j As Long , iPosition

iPosition = lstImages.ListIndex

temp = InputBox( "Enter filename prefix." , "Rename Files" )
If Trim$(temp) = "" Then
    'nothing
Else
    If MsgBox( "Are you sure?" , vbOKCancel, "Rename Files" ) = vbOK Then
        'remove all invalid characters
       
        'rename the files
        For i = 0 To lstImages.ListCount - 1
            If GList(i).Show = True Then
               j = j + 1
               temp2 = temp & "_" & Format $(j, "000" ) & Right$(lstImages.List(i), 4)
               Name lstImages.List(i) As temp2
               lstImages.List(i) = Lcase $(temp2)
               GList(i).FileName = Lcase $(temp2)
            End If
        Next i
       
        If Dir( "gbgallery.gal" ) <> "" Then Kill "gbgallery.gal"
        Open "gbgallery.gal" For Binary As #1
        Put #1, , CLng ( Ubound (GList))
        Put #1, , GList
        Close #1
       
       Changed = False

    End If
End If

lstImages.ListIndex = iPosition

Exit Sub

renameerror:
MsgBox "Error " & Err.Description, vbOKOnly, "Rename Files"
End Sub