How to improve this code??

I have written a code to iterate over the drive to find the file of specific extension and if the file is fount it'll be added to the list box but the code fails its iteration when it finds a directory. The iteration stops with the files not the directories. I want my program to search the file with a given extension even in the directories and sub-directories what shall I do?

here is my code

The variable buffer seen in my code is nothing but the drive string e.g H:\
count = 0;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
int Class::countOfDocuments(wchar_t buffer[10])
{
	wchar_t driveString[MAX_PATH + 1] = { 0 };
	wcsncat_s(driveString,260,buffer,260);
	wcsncat_s(driveString, 260, L"*doc", 260);
	WIN32_FIND_DATA documents;
	HANDLE hFind; bool var = true;
	hFind = FindFirstFile(driveString, &documents);
	if (INVALID_HANDLE_VALUE == hFind)
	{
		wchar_t* no = L"No documents found";
		SendMessage(list1, LB_ADDSTRING, NULL, (LPARAM)no);
		for (int i = 0; i <= 10; i++)
		{
			SendMessage(cprogress, PBM_SETRANGE, 0, i);
			SendMessage(cprogress, PBM_SETSTEP, (WPARAM)1, 0);
			SendMessage(cprogress, PBM_STEPIT, 0, 1);
		}
		return count = -1;
	}
	else
	{
		wchar_t* Yes = L"Document found";
		perform = true;
		SendMessage(list1, LB_ADDSTRING, NULL, (LPARAM)Yes);
		while (var = FindNextFile(hFind, &documents) == TRUE)
		{
			count++;
		}
		
		for (int i = 0; i <= count; i++)
		{
			SendMessage(cprogress, PBM_SETRANGE, 0, i);
			SendMessage(cprogress, PBM_SETSTEP, (WPARAM)1, 0);
			SendMessage(cprogress, PBM_STEPIT, 0, 1);
			wchar_t* doc = L"Document found";
			SendMessage(list1, LB_ADDSTRING, NULL, (LPARAM)doc);
		}
		wchar_t* z = L"search complete";
		SendMessage(list1, LB_ADDSTRING, NULL, (LPARAM)z);
}
	return count;
}
Last edited on
try this:
line 26
while ((var = FindNextFile(hFind, &documents)) == TRUE)
Topic archived. No new replies allowed.