Solved

rename files

Posted on 1998-06-27
4
227 Views
Last Modified: 2010-05-03
i want to make a program that will rename selected files from 001 to how many files were selcted. this is for picture files. i have list boxes that show the files and directories i want to be able to select the files from the list box and press the command button and have it rename the selected files and is there a way to show only pictures files in a list box
0
Comment
Question by:p400
  • 3
4 Comments
 

Author Comment

by:p400
ID: 1464445
Edited text of question
0
 
LVL 1

Accepted Solution

by:
cip earned 100 total points
ID: 1464446
Draw a DriveListBox, a DirListBox and a FileListBox on your form.
Set the "multiselect" property of the FileListBox to 2, "Extended", this will allow multiselection.
Draw a button on your form, name it cmdRename, then paste this code:

Private Sub Form_Load()
    ' Show only files with *.bmp extension
    File1.Pattern = "*.bmp"
End Sub

' Update changes in Dir1 when
' selecting a different drive.
Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub

' Update changes in File1 when
' selecting a different path
Private Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub

' Perform renaming
Private Sub cmdRename_Click()
    Dim i As Integer
    Dim cnt As Integer
    Dim fromName As String, toName As String
   
    ' Cycle through all items in the
    ' file listbox, and rename only
    ' the ones selected
    cnt = 0
    For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
            ' Increment counter
            cnt = cnt + 1
            ' Build full path of original file
            fromName = File1.Path & "\" & File1.List(i)
            ' Build full path of new renamed file
            toName = File1.Path & "\" & Format(cnt, "000") & ".bmp"
            ' Rename file using the Name statement
            Name fromName As toName
        End If
    Next
   
    ' Update listbox to show changes
    File1.Refresh
    ' Show number of files selected
    MsgBox "Number of renamed files: " & cnt
   
End Sub

0
 

Author Comment

by:p400
ID: 1464447
hay thanks it works great and does just what i want it to i really appreciate it thanks alot
0
 

Author Comment

by:p400
ID: 1464448
hay thanks it works great and does just what i want it to i really appreciate it thanks alot
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 56
LINQ return type for nested group query 6 59
Replace Formatted Numbers with text 9 51
VBA color chart bars 12 65
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now