using c++17+ <filesystem>

in this program it simply gets it's own containing directory and adds a data
folder if there isn't one already.

isn't there an easier way like directly concatenating the string to the pth object below? ( something like pth += "\\DataFiles"; but when I do that it only makes it \\DataFiles and therefore is in the root directory.)





namespace fs = std::experimental::filesystem;
int main()
{
string path;
fs::path pth = fs::current_path();
path = pth.string();
cout << path;
path = path + "\\DataFiles";
pth = path;
if (fs::create_directory(pth))
cout << "\n\n\n Set up data File folder: \n " + path + " \n\n";
return 0;
}
Adding data to a filesystem path, using either /= (append operator) or += (concat operator):

https://en.cppreference.com/w/cpp/filesystem/path/append

https://en.cppreference.com/w/cpp/filesystem/path/concat

BTW, since <filesystem> is now an official header in C++17 there is no longer a need for std::experimental::filesystem. It's now std::filesystem.
@Ganado, that stackoverflow link is over 8 years old, no <filesystem> header in the C++ standard.

Now there is with C++17.

Only two replies mention the changes C++17 made with <filesystem>.
Last edited on
I know that; the API is the same as far as I can tell. The post was edited in 2019 only to change the using declaration; the rest of it stayed the same.
Last edited on
wow, that was fast. Thanks guys.
Topic archived. No new replies allowed.