when I call FindNextFile in a loop it finds the same file in a directory each iteration and GetLastError returns 18 (ERROR_NO_FILES_MORE or like that). But I have MANY files in my dir...
In VB the following function grabs all files in a directory between certain date range...
I know your not writing in VB, but maybe this will help...
BG
----------------------------------------------
Function GetFileList(folderpath As String)
Dim FileSystemObj, Folder, file, Files
Dim strFileName As String
Dim dtFile As Date
Dim intCounter As Integer
On Error GoTo GetFileList_ErrorHandler
If IsDate(frmMain.txtDateFrom) = False Or IsDate(frmMain.txtDateTo) = False Then
MsgBox ("Please enter a valid date mm/dd/yy"
intCounter = 0
Exit Function
End If
Set FileSystemObj = CreateObject("Scripting.FileSystemObject"
Set Folder = FileSystemObj.GetFolder(folderpath)
Set Files = Folder.Files
intCounter = 0
For Each file In Files
dtFile = Format(file.DateLastModified, "mm/dd/yy"
If dtFile >= frmMain.txtDateFrom And dtFile <= frmMain.txtDateTo And InStr(1, file.Name, ".doc" Then
strFileName = file.Name
frmMain.lstFileList.AddItem strFileName
intCounter = intCounter + 1
End If
Next
Set FileSystemObj = Nothing
Set Folder = Nothing
Set Files = Nothing
GetFileList = intCounter
Exit Function
GetFileList_ErrorHandler:
Call HandleError(Err.Number, Err.Description, "GetFileList", True) 'Public Error Handler
End
End Function
-------------------------------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.