|
-
Nov 28th, 2001, 01:15 PM
#1
Thread Starter
Junior Member
-
Nov 28th, 2001, 01:35 PM
#2
You could try the VB function Dir, or the API functions FindFirstFile, FindNextFile and FindClose.
-
Nov 28th, 2001, 04:54 PM
#3
Thread Starter
Junior Member
Thanks a whole lot. I think that is going to work perfectly.
PS. What is the FindClose() api used for?
-
Nov 28th, 2001, 10:31 PM
#4
Fanatic Member
Here is a function that I wrote a while back to do exactly that, it returns all the subdirectories in one array and the the filenames in another array both passed to the GetDirectoryContents function....
VB Code:
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Sub Form_Load()
Dim sF() As String
Dim sD() As String
Dim iCt As Integer
GetDirectoryContents "C:\*.txt", sF, sD
Debug.Print "************FILES************"
For iCt = LBound(sF) To UBound(sF)
Debug.Print sF(iCt)
Next iCt
Debug.Print "************FOLDERS************"
For iCt = LBound(sD) To UBound(sD)
Debug.Print sD(iCt)
Next iCt
End Sub
Function GetDirectoryContents(strDirectory As String, strFiles() As String, strDirectories() As String) As Integer
Dim hFile As Long
Dim iFileCt As Long, iDirCt As Long
Dim iNext As Long
Dim wfd As WIN32_FIND_DATA
hFile = FindFirstFile(strDirectory, wfd)
If hFile Then
ReDim strDirectories(0)
ReDim strFiles(0)
Do
If wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY Then
ReDim Preserve strDirectories(iDirCt)
strDirectories(iDirCt) = Left$(wfd.cFileName, InStr(1, wfd.cFileName, Chr(0)) - 1)
iDirCt = iDirCt + 1
Else
ReDim Preserve strFiles(iFileCt)
strFiles(iFileCt) = Left$(wfd.cFileName, InStr(1, wfd.cFileName, Chr(0)) - 1)
iFileCt = iFileCt + 1
End If
wfd.cFileName = String(260, Chr(0))
iNext = FindNextFile(hFile, wfd)
Loop Until iNext = 0
FindClose hFile
End If
GetDirectoryContents = iFileCt + iDirCt
End Function
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
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
|