Click to See Complete Forum and Search --> : Alternative for CFileFind


mohang99
January 19th, 2006, 03:03 AM
I need to list the contents of the given folder, in a WIN 32 SDK application.

For that, I am doing the following.
CFileFind finder;
BOOL bWorking = finder.FindFile("G:\\*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
sprintf(szMess, "\nFile is %s", finder.GetFileName());
_RPT0(_CRT_WARN,(LPSTR) szMess);
}

But the compiler is reporting the error "fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>".

Are there any pure C++ classes or functions using which one find the files in a given folder.

Thanks in advance.

zt9788
January 19th, 2006, 03:33 AM
I need to list the contents of the given folder, in a WIN 32 SDK application.

For that, I am doing the following.
CFileFind finder;
BOOL bWorking = finder.FindFile("G:\\*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
sprintf(szMess, "\nFile is %s", finder.GetFileName());
_RPT0(_CRT_WARN,(LPSTR) szMess);
}

But the compiler is reporting the error "fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>".

Are there any pure C++ classes or functions using which one find the files in a given folder.

Thanks in advance.

i thought you used mfc project , if you want pure C++ classes or function,you should make a win32 appliction,and to include windows.h
is this was you want?

mohang99
January 19th, 2006, 03:41 AM
Yes, I have a Win 32 application in which windows.h was included.

To use CFileFind, I includeded afx.h. This generated the above error. So I need a way of getting rid of this error or use other classes or functions that do the same functionality but do not give any errrs.

ovidiucucu
January 19th, 2006, 04:04 AM
Getting rid of some errors is not a reason to decide using or not using MFC. MFC is well written, but your program has errors. If you have included <AfxWin.h> delete #include <windows.h>. Or, use AppWizard to create a new "MFC AppWizard (exe)" application. Then MFC will make your life much more easier, by using CFileFind, CString and so on.

If anyhow, you don't want to use MFC, you can call instead FindFirstFile, FindNextFile, and FindClose SDK functions.

PS. To zt9788. The MFC classes are like all other C++ classes and are not "impure" classes.

zt9788
January 19th, 2006, 04:05 AM
Yes, I have a Win 32 application in which windows.h was included.

To use CFileFind, I includeded afx.h. This generated the above error. So I need a way of getting rid of this error or use other classes or functions that do the same functionality but do not give any errrs.

i made a mistake,the CFileFind Function was in MFC,
you can used _findfirst function,_findnext function,_findclose etc.

mohang99
January 19th, 2006, 04:13 AM
Using the functions FindFirstFile, FindNextFile, FindClose, my problem was solved. Thanks for the help.