Why file listing function does not work correctly?

I have this function running on Windows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

int FILE_::findFiles(char * path)
{
	WIN32_FIND_DATAA search_data;
	memset(&search_data, 0, sizeof(WIN32_FIND_DATAA));	
	HANDLE handle = FindFirstFileA(path, &search_data);
	char * fname;

	while(handle != INVALID_HANDLE_VALUE)
	{
		fname = search_data.cFileName; // this filename
		if(FindNextFileA(handle, &search_data) == FALSE)
		break;
	}
	FindClose(handle);
	return 0;
}


 
S::I().File.findFiles(src_temp.subFolder);


In the src_temp.subFolder there is this char array:
"S:\TEMP\C++\alg\process\parse4\parse2\testdir"
in the folder, there are images. However when program processes the loop it will find only one file name "testdir", it does not look for other files. Where is the problem? Just for test, I added ending backslash, but in that case the loop will not proceed at all.
Last edited on
Your function doesn't do anything. You search for a files but you don't do anything with them once you've found them. The whole routine is a big no-op.

What are you trying to do?
I know that the loop does nothing. But the problem is that the loop is exited when the first file (directory) is found. I tried to add an asterix like: *.jpg ... it seemed like working (I thought it did some loops already) but finally it does not work still. I see wrong pointer 0xffff is returned by FindFirstFileA when I use wildcard. Where could be problem?
Last edited on
The only problem I see with the code you posted is that you are calling FindClose even if you got an invalid handle from FindFirstFileA (if FindFirstFileA fails, there is nothing to close, so you shouldn't call FindClose). But that wouldn't be causing your problem.


What input are you supplying? Like... what is 'path'?
Definitely solved. The wildcard really works, but my problem was that I passed incorrect file name prefix ... so the file name was not correct. Therefore was nothing to find.
Last edited on
Topic archived. No new replies allowed.