Wie kann ich mit boost::filesystem::path
einen relativen Pfad unter Windows angeben? Dieser Versuch schlägt fehl:
boost:filesystem::path full_path("../asset/toolbox"); // invalid path or directory.
Vielleicht um mir beim Debuggen zu helfen, wie man mit boost :: filesystem das aktuelle Arbeitsverzeichnis erhält?
getcwd = boost::filesystem::path full_path(boost::filesystem::current_path());
Beispiel:
boost::filesystem::path full_path(boost::filesystem::current_path());
std::cout << "Current path is : " << full_path << std::endl;
Um auf current_path
zuzugreifen, muss #include <boost/filesystem.hpp>
hinzugefügt werden.
Versuchen Sie die Funktion system_complete
.
namespace fs = boost::filesystem;
fs::path full_path = fs::system_complete("../asset/toolbox");
Dies ahmt genau nach, wie das Betriebssystem relative Pfade auflösen würde.
Wenn Sie zum vorherigen Verzeichnis wechseln möchten, versuchen Sie Folgendes:
boost::filesystem::path full_path( boost::filesystem::current_path() );
std::cout << "Current path is : " << full_path << std::endl;
//system("cd ../"); // change to previous dir -- this is NOT working
chdir("../"); // change to previous dir -- this IS working
boost::filesystem::path new_full_path( boost::filesystem::current_path() );
std::cout << "Current path is : " << new_full_path << std::endl;
Wenn Sie "../your/path" eingeben, geben Sie keinen unixartigen Pfad an? Ich denke, was Sie tun müssen, um systemspezifische Pfade zu erhalten, ist:
boost:filesystem::path full_path(".." / "asset" / "toolbox");
In diesem Fall ist das '/' ein Operator, der Pfade systemspezifisch verkettet und nicht Teil des von Ihnen angegebenen Pfads ist.