I was working on a bigger project using the recursive_directory_iterator
of std::filesystem
, when I stumbled upon this seemingly unknown/unfixable error.
I simplified the project to the bare minimum to recreate the error. Another questioner found a solution in providing the skip_permission_denied
option, which does nothing for me.
The exception is not limited to this file, it happens for random other files too, if I delete this one, for instance. Though it occurs for the same file every time if I decide not to delete it.
If I use the continue button on Visual Studio three times, it is actually able to continue the traversal of files.
What would be a proper way to address this error? And what could potentially cause this?
I removed all exception handling for readability, but the error occurs at the start of the for
loop once it reaches this file.
#define NOMINMAX
#include <string>
#include <iostream>
#include <filesystem>
#include <windows.h>
#include <fstream>
#include <winbase.h>
#include <numeric>
#include <string_view>
#include <vector>
#include <shlobj_core.h>
//#include <combaseapi.h>
namespace fs = std::filesystem;
using namespace std;
void startWinXSearch(string argv)
{
string pathToFolder = argv;
cout << pathToFolder << endl;
for (auto& el : std::filesystem::recursive_directory_iterator(pathToFolder, std::filesystem::directory_options::skip_permission_denied)) {
cout << el << endl;
}
}
int main(int argc, char* argv[])
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
string test = "C:\\Sciebo";
startWinXSearch(test);
}
UPDATE: This is what I get from using wcout
. No idea what this is supposed to mean. Is it that there's an invisible file there?!
The Error thrown currently is No mapping for the Unicode character exists in the target multi-byte code page
. If I find a solution or workaround I'll update it here.
FINAL UPDATE: I got it. Take a look at one of the comments ^^ It originated from invisible Unicode characters infront of a random file from my phone :D I even got a fix/workaround for it!