I'm trying to formulate a way how can I copy file to root directory from the unknown one (unknown means that I don't know its name). For example, I want to copy d:\tea\unknown\black.txt to d:\tea\black.txt. I found that it's possible in Cmd: copy files into unknown directory
What would make sense is to go through all folders within "Tea" and then search them all for "black.txt", error handling for the inevitability that you'll run into many folders before finding it.
For this, you'd want to make a list of all directories/folders within "tea"
std::vector<std::string> get_directories(const std::string& s)
{
std::vector<std::string> r;
for (constauto & entry : std::filesystem::directory_iterator(s))
{
// std::cout << entry.path() << std::endl;
r.push_back(entry.path().string());
}
return r;
}
int main()
{
std::string s = "C:\\Users\\Lelouch";
std::vector<std::string> r = get_directories(s);
for (int i = 0; i < r.size(); i++)
{
std::cout << r[i] << '\n';
}
return 0;
}
The vector "r" will contain all the folders in the directory. So from there, you can use the stream to go through them, opening them up and checking for "black.txt" until you find it.