2013-08-14 5 views
11

के साथ मुझे निर्देशिका से सभी फाइलों को पुनः प्राप्त करने की आवश्यकता है और यह उपनिर्देशिका है, लेकिन कई निर्देशिकाओं को छोड़कर। मैं उनके नाम जानता हूँ। क्या बूस्ट :: फाइल सिस्टम :: recursive_directory_iterator के साथ करना संभव है?boost :: filesystem :: recursive_directory_iterator फ़िल्टर

उत्तर

19

हाँ, जबकि निर्देशिका से अधिक पुनरावृत्ति, आप अपने अपवर्जन सूची में नाम के लिए परीक्षण करने और यह इस तरह के एक निर्देशिका में जाने से रोकने के लिए पुनरावर्ती इटरेटर की no_push() सदस्य का उपयोग कर सकते हैं, कुछ की तरह:

void selective_search(const path &search_here, const std::string &exclude_this_directory) 
{ 
    using namespace boost::filesystem; 
    recursive_directory_iterator dir(search_here), end; 
    while (dir != end) 
    { 
     // make sure we don't recurse into certain directories 
     // note: maybe check for is_directory() here as well... 
     if (dir->path().filename() == exclude_this_directory) 
     { 
      dir.no_push(); // don't recurse into this directory. 
     } 

     // do other stuff here.    

     ++dir; 
    } 
} 
+0

है symlink के आधार पर निर्देशिका फ़िल्टर करना संभव है। मैं symlink फ़ाइल में खोजना नहीं चाहता – user765443