2010-02-04 17 views
18

मैं बढ़ावा फाइल सिस्टम के साथ वर्तमान निर्देशिका के लिए पथ हो रही है, तो पता चल सके कि निर्देशिका मौजूद है।बढ़ावा :: फाइल सिस्टम() निर्देशिका पथ पर विफल रहता है मौजूद है, लेकिन is_directory() ठीक

is_directory() ठीक है, लेकिन exists() उसी रास्ते पर विफल रहता है, क्या मुझे कुछ याद आ रही है?

उदाहरण कोड (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 

संपादित करें:

#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 

मज़ा हिस्सा:

if (fs::exists(fs::status(data_dir)))  // true - directory exists 
if (fs::exists(data_dir))     // true - directory exists 

लेकिन:

if (!fs::exists(fs::status(data_dir)))  // false - directory still exists 
if (!fs::exists(data_dir))    // true - directory does not exists 
+1

आप Windows का उपयोग कर रहे हैं? यह अंतर्निहित विंडोज एपीआई की एक ज्ञात सीमा है। –

+0

विंडोज़ पर मेरे लिए काम करता है। – interjay

उत्तर

17

निम्नलिखित बूस्ट स्रोत कोड से है:

inline bool is_directory(file_status f) { return f.type() == directory_file; } 
inline bool exists(file_status f)  { return f.type() != status_unknown && f.type() != file_not_found; } 

आप देख सकते हैं, अगर is_directory रिटर्न सच तो exists सच के साथ-साथ लौट जाना चाहिए। शायद समस्या आपके कोड में कहीं और है - कृपया एक न्यूनतम संकलित उदाहरण पोस्ट करें जो समस्या दिखाता है।

आप दोनों कॉल के लिए उसी file_status ऑब्जेक्ट का उपयोग करने का प्रयास भी कर सकते हैं, यह देखने के लिए कि आउटपुट status बदल रहा था या नहीं।

+0

मैं पहले से ही कोड – stefanB

+4

ऊपर आप कुछ टुकड़े, नहीं एक compilable उदाहरण पोस्ट पोस्ट किया है। – interjay

+0

btw, मैं '() गुजर रहा हूँ' मौजूद है path' '' नहीं file_status', वहाँ एक समारोह को स्वीकार 'path' और रिटर्न' मौजूद है (स्थिति (पथ)) 'प्रलेखन – stefanB

संबंधित मुद्दे