Boost Filesystem, Directory up (../)?
-
Hallo,
Ein wahrscheinlich eher triviales Problem, aber ich finde nicht heraus
wie ich ein Verzeichnis nach oben springen kann...
In der Kommandozeile wäre das ja ein "../". Aber wie kann ich das in meiner
SW umsetzen ?Gruss Hoselupf
#include <iostream> #include <string> #include <boost/filesystem.hpp> using namespace std; namespace fs = boost::filesystem; bool dicPathValid(string pathIn){ if (!fs::is_directory(fs::path(pathIn))){ cout << "Path not valid\n" << "Try again:\n"; return false; } return true; } int main() { cout << "Root directory path: "; string rootPath; do{ cin >> rootPath; } while (!dicPathValid(rootPath)); fs::path myPath(rootPath); myPath /= "OrdnerX"; for (int i = 0; i != 20; i++){ myPath /= "Unterordner" + to_string(i); //do stuff in Unterordner(i) //go directory up (../) ??? } }
-
Den Pfad von hinten bis zum ersten Slash/Backslash (inklusive) abschneiden.
-
Genau. Und dann ist der letzte Pfadbestandteil ein Symlink. Oops.
Zurück zur Frage: Häng .. an den Pfad an.
http://www.boost.org/doc/libs/1_59_0/libs/filesystem/doc/reference.html#path-concatenation schrieb:
The filename ".." is considered to be a reference to the parent directory.
-
Dies scheint auch zu funktionieren.
myPath = myPath.parent_path();
-
Hoselupf schrieb:
Dies scheint auch zu funktionieren.
myPath = myPath.parent_path();Hat das gleiche Problem, wenn der letzte Pfadbestandteil ein Symlink ist.