Results 1 to 9 of 9

Thread: What is the most efficient way to list files/folders in a directory?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628

    What is the most efficient way to list files/folders in a directory?

    and determine if theyre a file or a folder?

    by most efficeint, i mean fastest with least ram needed (so no giant controls to add, etc)

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    FindFirstFile, FindNextFile API's.....

    Hmm... It really does sound like you're building a trojan from all these questions :|

  3. #3

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628
    is there an example without a listview?

    just something like debug.print file, type will do

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628
    and that wont retrieve files

    anyone have a simple function to retrieve folders/files from a dir?

    such as

    ListFolders(Folder as String)
    ListFiles(Folder as String)

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    check out "Dir" in VB help, the example should be more than enough for you.

  7. #7
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    http://mvps.org/vbnet/index.html?cod...umadvanced.htm
    You might want to check around that site and not just visit the links I give you. There is a ton of useful stuff for VB there. You will find that using the API is the fastest way to enumerate files and folders. If you want to list all subfolders and their subfolders etc., you will need recursion.

    Again, the site there WILL have what you want, but you might have to do a little work to find it.
    I have two simple requests: 1) Use useful and specific topics. 2) Modify your topic to include [Resolved] when you problem has been resolved. Both of these make the bulletin boards more useful and efficient. Thanks.

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Conflicting requirements...

    Using DIR means no extras, just the VB run time. So this is efficient, but its not necessarily the quickest.
    VB Code:
    1. SearchName = "C:\Temp\*.*"
    2. f = Dir(SearchName, vbReadOnly)
    3.    While f <> ""
    4.             MsgBox f
    5.             f = Dir()
    6.    Wend
    This is the quickest way of adding the files to a listbox:
    VB Code:
    1. Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,  ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    2. Private Sub Command1_Click()
    3.     Dim r As Long
    4.     r = SendMessageStr(List1.hwnd, &H18D, &H20, "C:\*.*")
    5. 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