List files on subdirectories

michaelfischer

New member
Local time
Today, 08:52
Joined
Jun 16, 2001
Messages
6
I have to process a number of files held in subdirectories and need some help with the coding so that each file name is returned.

For example i have dir c:\mydir\ which holds subdirectories of files1, files2 etc each containing several .txt files.
I don't want the dir names, just the names of *.txt files they contain.

Appreciate your help.
many thanks.
 
I use this procedure to put all the filenames in mydocs into a listbox:

Dim i As Integer
Dim strRow As String
Dim strSearch As String
'set the search string
strSearch = "D:\My Documents"
With Application.FileSearch
.LookIn = strSearch
.SearchSubFolders = False
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
.Execute
MsgBox .FoundFiles.Count & " files found"
For i = 1 To .FoundFiles.Count
strRow = strRow & Mid(.FoundFiles(i), Len(strSearch) + 2, 500) & ";"
Next i
End With

Me.lbxFileList.RowSource = Left(strRow, Len(strRow) - 1)

You could if you wished test the last three character of the filename for txt if you so desired.

HTH

Ian
 
When i use the code below, after creating a list box and a button on the form, it gives me "Invalid Procedure call or argument".
What am i missing over here?
Please help.
Regards,
Mat.


I use this procedure to put all the filenames in mydocs into a listbox:

Dim i As Integer
Dim strRow As String
Dim strSearch As String
'set the search string
strSearch = "D:\My Documents"
With Application.FileSearch
.LookIn = strSearch
.SearchSubFolders = False
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
.Execute
MsgBox .FoundFiles.Count & " files found"
For i = 1 To .FoundFiles.Count
strRow = strRow & Mid(.FoundFiles(i), Len(strSearch) + 2, 500) & ";"
Next i
End With

Me.lbxFileList.RowSource = Left(strRow, Len(strRow) - 1)

You could if you wished test the last three character of the filename for txt if you so desired.

HTH

Ian
 

Users who are viewing this thread

Back
Top Bottom