Link to home
Start Free TrialLog in
Avatar of CodingCat
CodingCat

asked on

how to list the files in a directory using CFileFind class?

hi,
I'm trying to list all the .jpg files using CFileFind class in a console program.  I put 3 .jpg files in the same directory for testing.
The program returns 3 32-bit integer, which looks like the addresses of something, but not the names of the jpg files.  what's wrong with the code?
CFileFind finder;
		BOOL bWorking = finder.FindFile(_T("*.jpg"), 0);
		bWorking ==0? printf("not find \n"): printf("found \n");
		while (bWorking)
		{
			bWorking = finder.FindNextFile();
			cout<<(LPCTSTR)(finder.GetFileName()) << endl;
			printf("\n"); }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodingCat
CodingCat

ASKER

the first .jpg file is displayed,  but an error window poped out immediately says
"Debug assertion Failed"  and I have to abort the program.
How to solve that?
What is the rest of your code in that function?
o, I put a finder.Close() in the loop which caused the problem.  Thanks.
You're most welcome ;o)