Solved

Subfolder

Posted on 2001-06-11
8
578 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 50

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

839 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