Solved

Subfolder

Posted on 2001-06-11
8
579 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:sporfex
8 Comments
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6180084
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.
0
 

Author Comment

by:sporfex
ID: 6180088
I want it in a filelist box, thats my big problem...
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6180225
Look at this article: you have got 3 methods to do the list of files. Check if you could use one.

http://support.microsoft.com/support/kb/articles/Q185/4/76.ASP
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6180227
Hi, as i know, filelist box only can show its parent path's files.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6180232
Also, Check this link to do the filling to filelistbox:

http://www.vbexplorer.com/vbs_fd.asp
"Get all the matching files in the directory structure."

Cheers

0
 
LVL 3

Accepted Solution

by:
sombell earned 85 total points
ID: 6180257
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
  ListView1.ListItems.Clear
  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
  Next
  'now do the same for each subfolder
  For Each iFolder In pFolder.SubFolders
    getFiles iFolder
  Next
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.
Sombell
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6180294
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.
0
 

Author Comment

by:sporfex
ID: 6180305
Interesting!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 69
Spell Check in VB6 13 135
Added a column screws up code 5 69
Child Form in front 4 56
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

685 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