• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:


Hi Experts.

How can I make a filelist with all the files including the FILES in the subfolders.I dont't want to present the subfolders itself, just the files.

Greatest Regards
1 Solution
Valliappan ANSenior Tech ConsultantCommented:
Shell "command.com /c dir yourdirname /s /b /a-d > filename"

Then you could read from the file, all the files present in the directory.
sporfexAuthor Commented:
I want it in a filelist box, thats my big problem...
Valliappan ANSenior Tech ConsultantCommented:
Look at this article: you have got 3 methods to do the list of files. Check if you could use one.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Ryan ChongCommented:
Hi, as i know, filelist box only can show its parent path's files.
Valliappan ANSenior Tech ConsultantCommented:
Also, Check this link to do the filling to filelistbox:

"Get all the matching files in the directory structure."


To get all the files in a directory and its subdirectories you can iterate through the directory and subdirectories using the API. Generally its faster, though in most cases the difference isnt really noticeable unless your directories and sub-directories are very large.

The simplest method is to use the FileSystemObject. You can use this to get your code working, and update it to use the API later if you find the performance is a problem.

I am not aware of any way to show this in a filelist box (i presume you mean the standard control). But you can show them in a listview control of your own:

Add the Reference "Microsoft Scripting Runtime" to your project
Add the Component "Microsoft Windows Common Controls" to your project

Put a DirListBox on the form (this is just to let you choose the directory
Put a Command Button on the Form (change the caption of the button to "List")
Put a ListView on the form

then paste the following code into your form.

Option Explicit
Dim gfso As New filesystemobject

Private Sub Command1_Click()
  Dim startFolder As Folder
  Me.MousePointer = vbHourglass
  Set startFolder = gfso.GetFolder(Dir1.Path)
  getFiles startFolder
  Me.MousePointer = vbDefault
End Sub

Function getFiles(pFolder As Folder)
  Dim iFile As File, iFolder As Folder, tItem As ListItem
  'list the files in this folder
  For Each iFile In pFolder.Files
    Set tItem = ListView1.ListItems.Add(, , iFile.Name)
    tItem.SubItems(1) = Left(iFile.Path, Len(iFile.Path) - Len(iFile.Name)) 'just the path without the file name on it
  'now do the same for each subfolder
  For Each iFolder In pFolder.SubFolders
    getFiles iFolder
End Function

Private Sub Form_Load()
  Dim tColumn As ColumnHeader
  'add a column for the path to the listview & set the view format
  ListView1.View = lvwReport
  Set tColumn = ListView1.ColumnHeaders.Add(, , "File Name", 3000)
  Set tColumn = ListView1.ColumnHeaders.Add(, , "Path", 5000)
End Sub

Hope this helps.
Valliappan ANSenior Tech ConsultantCommented:
I look into ryansys statement.

From MSDN:
A FileListBox control locates and lists files in the directory specified by the Path property at run time.Use this control to display a list of files selected by file type. You can create dialog boxes in your application that, for example, enable the user to select a file or group of files.

So, may be, you could use some other controls, a listbox, or maybe a ListView as sombell has suggested.

The MS link that I have provided already, lists of the possible methods, API, Built-In Vb functions and FSO.
sporfexAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now