|
|
|
Click here to copy the following block | 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 Const MAX_PATH = 260
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 * MAX_PATH cAlternate As String * 14 End Type
Function FilesToArray(ByVal Path As String, Optional ByVal IncludeDirs As _ Boolean) As String() Dim lRet As Long Dim handle As Long Dim FindData As WIN32_FIND_DATA Dim FileName As String Dim fileCount As Long Dim ok As Boolean ReDim res(0) As String handle = FindFirstFile(Path, FindData) If handle < 0 Then FilesToArray = res() Exit Function End If Do FileName = Left$(FindData.cFileName, InStr(FindData.cFileName, _ vbNullChar) - 1) If (FindData.dwFileAttributes And vbDirectory) = 0 Then ok = Not IncludeDirs ElseIf FileName <> "." And FileName <> ".." Then ok = IncludeDirs Else ok = False End If If ok Then fileCount = fileCount + 1 If fileCount > UBound(res) Then ReDim Preserve res(fileCount + 100) As String End If res(fileCount) = FileName End If lRet = FindNextFile(handle, FindData) Loop While lRet
FindClose handle ReDim Preserve res(0 To fileCount) As String FilesToArray = res End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|