Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindNextFile function

Status
Not open for further replies.

neutrino4

Programmer
Oct 21, 2003
1
0
0
RU
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... :(
 
Can't really say a lot without a sample of your code.

The example below is one way to do this sort of thing :

static CCHAR source_ext[5] = "*.cpp";
WIN32_FIND_DATA wfd;
HANDLE fhdl;

fhdl = FindFirstFile(source_ext, &wfd);
if (fhdl != INVALID_HANDLE_VALUE)
{ do
{
blah blah...

}while (FindNextFile(fhdl,&wfd) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}

 
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, &quot;.doc&quot;) 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, &quot;GetFileList&quot;, True) 'Public Error Handler
End

End Function
-------------------------------------------
 
Are you using some sort of filter when searching your directory?

Skute

&quot;There are 10 types of people in this World, those that understand binary, and those that don't!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top