By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,068 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,068 IT Pros & Developers. It's quick & easy.

Pass all files listed in a FileListBox to a collection?

P: 2

This is a simple problem that I, for some reason, am having a hard time with. Basically I am trying to rename all the files listed in a FileListBox based on a search and replace string. I am able to accomplish this task by referencing all files in a folder using the filesystemobject but, as you can see in the code below, this attempts to rename all files in the referenced folder. I would rather reference all of the files listed in the FileListBox which is populated based on a pattern. Can someone please review the code below and point out where I am going wrong? Thanks.

P.S. I would be fine with continuing with the solution as seen below (I.e. I don't necessarily have to reference the files being displayed in the FileListBox) but I do get an error syaing "File Already Exists" after the for each statement is finished.

Private Sub Command1_Click(Index As Integer)
Dim fso As New FileSystemObject
Dim rfldr As Scripting.Folder
Set rfldr = fso.GetFolder(Form1.Dir1.Path)

'send it to a sub routine
Call GetFiles(rfldr)
End Sub

Public Sub GetFiles(rfldr As Scripting.Folder)
Dim fso As New Scripting.FileSystemObject
Dim f2 As Scripting.File

'Dim i As Integer
'Dim FileCol As New Collection
'Set FileCol = File1.List

For Each f2 In rfldr
'Do Until rfldr.Files Is Nothing
f2.Name = Replace(f2.Name, Form1.Text2.Text, Form1.Text3.Text)
Set rfldr = Nothing
File1.Pattern = "*" & Text3.Text & "*"
End Sub
Sep 13 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.