If recordsets are not feasible in this situation, you can use the following API code which uses file searching APIs.
I used these APIs because they return the FileName and the FileTime in a single hit to the disk. Using VB, we have to use two separate functions for this purpose; Dir and FileDateTime which requires hitting the disk twice.
Not to mention that FSO also returns FileName and FileTime in a single call but it has more overhead then API and I prefer using API.
___
[tt]
Option Explicit
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 Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length 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
Private Type FileInfo
FileName As String
Modified As Currency
End Type
Function DirEx(Path As String) As String()
Dim hFind As Long, wfd As WIN32_FIND_DATA, Files() As FileInfo, N As Long, I As Long
'create file list
hFind = FindFirstFile(Path, wfd)
Do
If (wfd.dwFileAttributes And vbDirectory) = 0 Then
ReDim Preserve Files(N)
Files(N).FileName = Left$(wfd.cFileName, lstrlen(wfd.cFileName))
CopyMemory Files(N).Modified, wfd.ftLastWriteTime, 8
N = N + 1
End If
Loop While FindNextFile(hFind, wfd)
FindClose hFind
'sort file list
Dim File As FileInfo
For N = 0 To UBound(Files)
For I = N + 1 To UBound(Files)
If Files(N).Modified > Files(I).Modified Then
File = Files(I)
Files(I) = Files(N)
Files(N) = File
End If
Next
Next
'return file list
ReDim V(UBound(Files)) As String
For N = 0 To UBound(Files)
V(N) = Files(N).FileName
Next
DirEx = V
End Function
Private Sub Form_Load()
Dim Files() As String, N As Long
Files = DirEx("C:\Apc\Actv\*.VNM")
For N = 0 To UBound(Files)
Debug.Print Files(N)
Next
End Sub[/tt]
___
George, their is a much easier way to get only filenames out of the DIR command.
[tt][ignore]Shell "cmd /c DIR C:\ /O:-D /B > C:\DirList.txt"[/ignore][/tt]
Note that [ignore]/O:-D[/ignore] reverses the sort order (Newest to Oldest) and /B, which specifies the bare format removes all information (like date and time) but the filename.