|
-
Sep 17th, 2003, 02:59 AM
#1
Thread Starter
Lively Member
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
-
Sep 17th, 2003, 05:01 AM
#2
Frenzied Member
look up or search in here for the DIR command.
possibly something like:
VB Code:
Function DirList(strDir As String) As String()
'returns a 0 based array with the files in strDir
'Can contain a pattern such as "*.*"
Dim Count As Integer
Dim sFiles() As String
Dim sFile As String
sFile = Dir$(strDir)
Count = -1
Do
Count = Count + 1
ReDim Preserve sFiles(Count)
sFiles(Count) = sFile
sFile = Dir$
Loop
DirList = sFiles
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:
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
Private Sub Command1_Click()
Dim r As Long
r = SendMessageStr(List1.hwnd, &H18D, &H20, "C:\*.*")
End Sub
-
Sep 17th, 2003, 05:40 AM
#3
Thread Starter
Lively Member
excellent stuff.
cheers I will have a look
When I grow up, I wanna be competent
-
Sep 17th, 2003, 06:16 AM
#4
Thread Starter
Lively Member
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:
Dim strBuffer As String
Dim fileURLArray() As String
Dim fileCount As Integer
fileCount = 0
strBuffer = Dir("C:\FileDirectory\")
Do Until strBuffer = ""
fileCount = fileCount + 1
ReDim Preserve fileURLArray(fileCount)
fileURLArray(fileCount) = strBuffer
strBuffer = Dir
Loop
Thanx for the help
When I grow up, I wanna be competent
-
Sep 19th, 2003, 09:37 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|