Results 1 to 10 of 10

Thread: Listing directory content in Visual basic 6

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    11

    Listing directory content in Visual basic 6

    I have a folder called c:\myFolder. Inside the folder has 3 files, which is a.gif, b.gif,c.gif, and a folder called subFolder.

    Now given the path C:\myFolder, how do get all the file name or folder name inside? And how to distinguish a folder from a file?
    (I only need first level of file name, ie no need to recurse the subfolder)

  2. #2
    Lively Member
    Join Date
    Jan 2002
    Location
    Posts
    114

    Re: Listing directory content in Visual basic 6

    Use FSO, file system objects.
    to differentiate file and folder use fso.file and fso.folder...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listing directory content in Visual basic 6

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
        ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_DIR = &H18D
    
    Private Const DDL_DIRECTORY = &H10
    Private Const DDL_ARCHIVE = &H20
    Private Const DDL_EXCLUSIVE = &H8000
    
    Private Sub Command1_Click()
        List1.Clear: List2.Clear
        
        ' Directories
        SendMessage List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_DIRECTORY, ByVal "C:\myfolder\*.*"
        
        ' Files
        SendMessage List2.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_ARCHIVE, ByVal "C:\myfolder\*.*"
    End Sub

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Listing directory content in Visual basic 6

    You can also use Dir(), sample available in code bank. Take your pick.

  5. #5
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Listing directory content in Visual basic 6

    try this.

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    11

    Re: Listing directory content in Visual basic 6

    what is code bank??

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listing directory content in Visual basic 6

    A series of forum sections at the bottom of the main page where members have posted useful code.

    Did you try my example?

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Listing directory content in Visual basic 6

    When you do an advanced search limit your search to the VBForums CodeBank section for Visual Basic 6 by scrolling down the list and selecting it

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listing directory content in Visual basic 6


  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    11

    Re: Listing directory content in Visual basic 6

    Wow...thanks for all the great help. And Hack, thanks for you code also
    CodeBank is really a wonderful virtual bank!

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