Solved

Subfolder

Posted on 2001-06-11
8
580 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
[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
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 52

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

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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

734 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