Tôi đang tìm đường dẫn đến thư mục hiện tại với hệ thống tập tin tăng, sau đó kiểm tra xem thư mục có tồn tại hay không.boost :: filesystem exists() trên đường dẫn thư mục bị lỗi, nhưng is_directory() là ok
is_directory()
là ok, nhưng exists()
không hoạt động trên cùng một đường dẫn, tôi có thiếu gì đó không?
Ví dụ mã (tăng 1,35):
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
namespace fs = boost::filesystem;
// the path is full path /home/my/somedirectory
fs::path data_dir(fs::current_path());
fs::is_directory(data_dir) // true, directory exists
fs::exists(data_dir) // false
exists(status(data_dir)) // false
EDIT:
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
namespace fs = boost::filesystem;
fs::path data_dir(fs::current_path());
// data_dir == "/home/myusername/proj/test"
if (fs::is_directory(data_dir)) // true - is directory
if (fs::is_directory(fs::status(data_dir))) // true - it is still a directory
phần thú vị:
if (fs::exists(fs::status(data_dir))) // true - directory exists
if (fs::exists(data_dir)) // true - directory exists
NHƯNG:
if (!fs::exists(fs::status(data_dir))) // false - directory still exists
if (!fs::exists(data_dir)) // true - directory does not exists
Bạn đang sử dụng Windows? Đây là giới hạn được biết đến của API Windows cơ bản. –
Làm việc cho tôi trên Windows. – interjay