Solved

rename files

Posted on 1998-06-27
4
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

729 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