Solved

rename files

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

815 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

10 Experts available now in Live!

Get 1:1 Help Now