Я хочу знать, как получить доступ к родительскому каталогу текущего рабочего каталога, используя заголовок <filesystem>
для C++ 17
. Затем я хочу перенаправить в другую папку из родительского каталога для поиска файла.
Вот концептуальный пример:
#include <iostream>
#include <filesystem>
using namespace std;
int main()
{
namespace fs = std::filesystem;
fs::path working_dir(fs::current_path());
fs::path parent_path(
// ... Get path to parent dir of current working dir ... //
);
fs::current_path(parent_path);
fs::current_path(
// ... Redirect to subfolder called "sub_fold" ... //
);
// ... Search for specified file called "sub_file" to see if it exists ... //
if (sub_file.exists()) // Psudo-code for returning if "sub_file" exists
{
// ... Do stuff with "sub_file" ... //
}
else cout << "File does not exist in " << fs::current_path << endl;
fs::current_path(working_dir);
// ... Continue program ... //
return 0;
}