Solved

rename files

Posted on 1998-06-27
4
242 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

790 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