I do believe that the problem is with the way "std::recursive_directory_iterator" handles the files.
I tried to only print the files paths from the iterator with :
cout << file.path().string();
and it printed the files until it reached a file with Unicode Characters and crashed.
I tried :
cout << file.path().u8string()
.. it didn't crash , but the Unicode Characters are messed up completely.
I tried :
.. u16string() and u32string() doesn't exists
the error :
Unhandled exception at 0x00007FFB078C3E49 in ConsoleApplication1.exe: Microsoft C++ exception: std::system_error at memory location 0x000000DD992FE8D8.
here in filesystem :
[[noreturn]] inline void _Throw_system_error_from_std_win_error(const __std_win_error _Errno) {
_THROW(system_error{_Make_ec(_Errno)});
}
I forgot also to mention that i tried "std::wcout << file.path().wstring();" yesterday, but that didn't work too cause it skipped the Unicode files all together .
Specs :
Windows 10. Visual Studio 2019 and the c++17 standard, with everything on default.
Unhandled exception at 0x00007FFB078C3E49 in ConsoleApplication1.exe: Microsoft C++ exception: std::system_error at memory location 0x0000003D56B6E6E8.
It works fine for me, but I'm on linux, which uses UTF-8, whereas windows (AFAIK) uses UTF-16 (although I thought they were updating to UTF-8 but I don't know).
Sorry I forgot to write those information : Windows 10. Visual Studio 2019 and the c++17 standard, with everything on default.
the console crashes , and Visual Studio takes me to filesystem file , then to shows the error messages. All the error messages are in the first post.
Could you give me a simple code for the method the you meant, with the includes, so that I can understand clearly. In the link there is no iterator code, and the links inside it takes me to the normal "recursive_directory_iterator" description without any examples.
The link I pointed out has code that is showing you how to use Windows Unicode features with their std::filesystem code. Since you say the program is crashing because of Unicode characters in the directory structure you should look at that code for hints on how you need to handle the construction of the "path" and how to print out the directory contents that contain possible Windows Unicode characters.
By the way I would expect that you should be able to trace the "crash" back to somewhere in your code.
By the way while your code doesn't "crash the console" for me it does throw an exception: "filesystem error: cannot increment recursive directory iterator: Permission denied" but only when running the program as a "normal user", if I run the program as "root" it runs to proper termination.
In case you haven't guessed I'm using Linux, not Windows.
jlb (4854):
Sorry I am a beginner, I couldn't understand what they have on that link clearly.
handle the construction of the "path" and how to print out the directory contents that contain possible Windows Unicode characters.
This idea sounds great. I hope that you can help to achieve promising results to solve this problem, cause really I can't totally understand how to implement it.
As for Windows, yeah . I totally understand what you mean. I tried the code the day before yesterday on another drive other than C, just to eliminate the "Windows Permissions" problem too. no luck.
I am an "Internal Administrator", so permissions are not a problem for me for 99% of time.
If you're such a beginner, what is the reason you want to try to recursively iterate trough your directories?
But as for giving you much more information, you're probably going to need to wait for a Windows expert that can either duplicate the problem or offer further direction. Since I haven't touched any Windows operating system this century I can't offer much further advice.
jlb (4855):
Thank you.I hope that i could find a solution for this problem.
I am trying to iterate trough directories to collect files and, push them back to a vector, as a practice project.
Then maybe get the size of each file, add it to some kind of a database, and so on. Practice makes perfect :-p .