Results 1 to 5 of 5

Thread: Exhaustive directory search [RESOLVED]

  1. #1

    Thread Starter
    Lively Member doh!'s Avatar
    Join Date
    Aug 2003
    Posts
    81

    Exhaustive directory search [RESOLVED]

    Hi,

    I am trying to write an application that will search through a directory, place the filepaths to ALL of the files found into an array and then display the filepaths in a text box. I am able to select the drive and directory, but have not got a clue how to act on all of the files. I would really appreciate any pointers.


    Cheers
    Last edited by doh!; Sep 17th, 2003 at 06:18 AM.
    When I grow up, I wanna be competent

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    look up or search in here for the DIR command.

    possibly something like:
    VB Code:
    1. Function DirList(strDir As String) As String()
    2.     'returns a 0 based array with the files in strDir
    3.     'Can contain a pattern such as "*.*"
    4.     Dim Count As Integer
    5.     Dim sFiles() As String
    6.     Dim sFile As String
    7.    
    8.     sFile = Dir$(strDir)
    9.     Count = -1
    10.     Do
    11.         Count = Count + 1
    12.         ReDim Preserve sFiles(Count)
    13.         sFiles(Count) = sFile
    14.         sFile = Dir$
    15.     Loop
    16.     DirList = sFiles
    17. End Function
    Or, if all you are interested in is the final list, rather than the individual files that make up the list:
    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

  3. #3

    Thread Starter
    Lively Member doh!'s Avatar
    Join Date
    Aug 2003
    Posts
    81
    excellent stuff.

    cheers I will have a look
    When I grow up, I wanna be competent

  4. #4

    Thread Starter
    Lively Member doh!'s Avatar
    Join Date
    Aug 2003
    Posts
    81
    Just for future reference, this is how to loop through an directory and read all file URLs into an array. I know it may not be pretty putting a redim inside a loop, but it works. If anyone can see a neater method, please let me know.......I don't really like having ugly code, it just seems to come naturally!

    VB Code:
    1. Dim strBuffer As String
    2. Dim fileURLArray() As String
    3. Dim fileCount As Integer
    4.  
    5.     fileCount = 0
    6.  
    7.     strBuffer = Dir("C:\FileDirectory\")
    8.     Do Until strBuffer = ""
    9.         fileCount = fileCount + 1
    10.         ReDim Preserve fileURLArray(fileCount)
    11.         fileURLArray(fileCount) = strBuffer
    12.         strBuffer = Dir
    13.     Loop


    Thanx for the help
    When I grow up, I wanna be competent

  5. #5
    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.

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