Solved

rename files

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now