I know about FindFirstFile/FindNextFile, so how can i display along the path, for example, C:\Program Files\, all folders and all files enclosed within them, in general, all directories and files along this path. Using only WinAPI + FindFirstFile/FindNextFile, without Boost/Filesystem/dirent.h and etc. Looks like a recursion output with dirent.h, such as:
Repeater, thank you! But i wrote "without Boost/Filesystem/dirent.h and etc" and "using WinAPI only". it is necessary and spelled out in my assignment. I tried to do using dirent.h and i made it, but the teacher said to do only using WinAPI with FindFirstFile/FindNextFile, after I tried to do it using WinAPI, but the program does not display all the files.
C++, unfortunately, is not my core language.
You've already written it. You just need to call FindFile for each directory you find.
Each time you find a directory, add it to a vector of them. Something like this.
1 2 3 4 5 6 7 8
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((!lstrcmpW(file.cFileName, L".")) || (!lstrcmpW(file.cFileName, L"..")))
{
directories.append(THE_DIRECTORY_PATH); // ADD THE FOUND DIRECTORY TO YOUR VECTOR
continue;
}
}
Your outer loop keeps going until there are no more directories.
1 2 3 4 5 6 7 8
vector<string> directories; // THIS is the directory vector to add to. You work out how to pass it to the FindFile function
directories.push_back("C:");
while (directories.size() > 0)
{
string next_dir = directories.back();
directories.pop_back();
FindFile(next_dir);
}
JLBorges, hello!
There are two errors:
Error E0167 argument of type "WIN32_FIND_DATAA *" is incompatible with parameter of type "LPWIN32_FIND_DATAW"
Error C2664 "BOOL FindNextFileW (HANDLE, LPWIN32_FIND_DATAW)": cannot convert argument 2 from "_Ty *" to "LPWIN32_FIND_DATAW" with [_Ty = WIN32_FIND_DATAA]
Both relate to the string 29 while (FindNextFile(handle, std::addressof(find_data)));
Dear Sir JLBorges, you wonderful C++ wizard! THANK YOU!
It great works!!!
I want to say thanks to this forum, which the 6th programming portal and where i finally got help!
I also express my gratitude to everyone who somehow answered me in this thread!