I'm trying to list all the directories and files from the computer and want to work with the DIR and FILES.
Note:
I'm on Windows platform. Using Visual Studio 2019 Community edition. And FYI running the compiled binary as Administrator because of the permission issues on windows. Please do run as Administrator to reproduce the error.
Here I'm using recursive_directory_iterator
from the <filesystem>
library which now comes in c++17 standard.
Here's a basic code snippet:
#include <iostream>
#include <windows.h>
#include <vector>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
string f_path = "E:\\";
void func1(string file_path)
{
vector<string> my_paths{};
for (auto& p : fs::recursive_directory_iterator(file_path))
{
cout << p.path() << endl;
}
}
int main()
{
func1(f_path);
return 0;
}
This is the error this code throws.
I'm new to Cpp and not able to solve this. I appreciate your efforts on taking your time and helping me.