With maneuvering the filesystem relative to the working directory to enter various sub-directories I've been using a string:
1 2
filesystem::current_path("SubDirName"); // from parent to sub
filesystem::current_path("/ParentDirName"); // back up from sub to parent
I'd like to do this with a string variable rather than have an ocean of logical code like this:
1 2 3 4 5
string parent, sub;
parent = "/ParentDirName";
sub = "SubDirName";
filesystem::current_path(sub); // from parent to sub
filesystem::current_path(parent); // back up from sub to parent
But it doesn't work... ugh.
Is there a way to do this with std::filesystem?
Thanks for taking the time to read, Tom
Linux with gcc version 7.5.0
#include <iostream>
#include <filesystem>
usingnamespace std;
int main()
{
auto path = filesystem::current_path();
cout << "in working directory" << endl;
filesystem::current_path(subdir); // to subdirectory
cout << "in subdirectory" << endl;
filesystem::current_path(path); // back to parent directory stored as "path"
cout << "back in working directory" << endl;
}