Solved

Subfolder

Posted on 2001-06-11
8
575 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
Comment Utility
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
Comment Utility
I want it in a filelist box, thats my big problem...
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi, as i know, filelist box only can show its parent path's files.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Interesting!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now