I made a program using multithreading to list files in directory/drive.When executing it results in less no of files than the actual no of files inside the directory/drive.i dont know where the mistake lies.Please help me and guide me properly through the logic.
Directory-(global deque) consists of list of folders in directory/Drive
DWORD WINAPI List(LPVOID)
{
deque<string>subdir;
while(true)
{
EnterCriticalSection(&QueueLock);
if(directories.empty())
{
LeaveCriticalSection(&QueueLock);
//Sleep(500);
break;
}
else
{
string path = directories.front();
//cout << path << endl;
//spec = path + "\\" + "*";
directories.pop_front();
subdir.push_front(path);
LeaveCriticalSection(&QueueLock);
}
//Listcontents(path,spec,subdir);
while(!subdir.empty())
{
EnterCriticalSection(&Fillock);
string subpath = subdir.front();
string spec = subpath + "\\" + "*";
subdir.pop_front();
LeaveCriticalSection(&Fillock);
HANDLE hf = FindFirstFileA(spec.c_str(),&ffd);
if(hf == INVALID_HANDLE_VALUE)
continue;
do
{
if(strcmp(ffd.cFileName,".") && strcmp(ffd.cFileName,".."))
{
if(ffd.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
{
EnterCriticalSection(&Sublock);
cout<< subpath <<endl;
subdir.push_front(subpath + "\\" + ffd.cFileName);
LeaveCriticalSection(&Sublock);
}
else
{
EnterCriticalSection(&Veclock);
files.push_back(subpath + "\\" + ffd.cFileName);
Files++;
LeaveCriticalSection(&Veclock);
}
}
}while(FindNextFileA(hf,&ffd));
FindClose(hf);
hf = INVALID_HANDLE_VALUE;
}
}
return 0;
}