I want to implement recursive directories and files listing on my own. I do not want to use
std::filesystem::recursive_directory_iterator
I tried this code:
void TraverseDirectory(const std::string& rootDirectory)
{
//Go thru the root directory
for(const auto& entry : std::filesystem::directory_iterator(rootDirectory)) {
std::string filenameStr = entry.path().filename().string();
//if the first found entry is directory go thru it
if(entry.is_directory()) {
std::cout << "Dir: " << filenameStr << '\n';
TraverseDirectory(filenameStr);
}
//print file name
else if(entry.is_regular_file()) {
std::cout << "file: " << filenameStr << '\n';
}
}
}
int main()
{
TraverseDirectory("testdir");
}
but it gives me this error when the main loop enters TraverseDirectory(filenameStr);:
How can I iterate over directories and its files without the error shown above?
