Results 1 to 3 of 3

Thread: Mega hard one - populating listbox with data...

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Talking

    I need to write a program which loops through a cd in my D: drive, then lists all of the files on this.

    So you've kept reading? I want to end up with these files ijn a list in Excel, though if it is easier, can someone tell me how to put this list inside a listbox & I can work out how to transfer this.

    Thank you everone!!!!!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    if

    If don't have any sub folders on your cd , just put
    a Filelist and set is path to "d:\".

  3. #3
    Guest
    Must be your lucky day!

    Add a reference to the MICROSOFT SCRIPTING RUNTIME library (SCRRUN.DLL) using the project menu.

    put a command button and a listbox on your form, dont re-name them yet. Customise the code below to search the appropriate folder / drive.

    It uses recursion to go through every single file and folder in the top-level folder (specified at the botton of the code sample.

    Mail me for more explanation.

    Code:
    Option Explicit
    
    Dim MyFSO As New FileSystemObject
    Dim FSOFolder As Folder
    
    Sub RecurseDirs(MyFolder As Folder)
    
    Dim FSOSubFolders As Folders
    Dim FSOFiles As Files
    Dim FSOFile As File
    Dim TempFolder As Folder
    
    Set FSOSubFolders = MyFolder.SubFolders
    For Each TempFolder In FSOSubFolders
        List1.AddItem "DIR... " & TempFolder.Path
        Call RecurseDirs(TempFolder)
    Next TempFolder
    
    Set FSOFiles = MyFolder.Files
    For Each FSOFile In FSOFiles
        List1.AddItem FSOFile.Path
    Next FSOFile
    
    End Sub
    
    Private Sub Command1_Click()
    
    List1.Clear
    Set FSOFolder = MyFSO.GetFolder("C:\Windows\Desktop")
    Call RecurseDirs(FSOFolder)
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width