I need some help with some code.
I'm using boost filesystem library V3 c++.
I am using an iterator to list files and directories recursively.
My program runs perfectly until it scans the "System Volume Information" directory on Windows machines. At that point the program throws an exception because it cant recurse into that particular directory because it is a system directory, and access is denied.

I read that this is a known problem that can often be overcome by using a modifier no_push(); The information can be found here: http://www.boost.org/doc/libs/1_46_0/libs/filesystem/v3/doc/reference.html

However, I cant seem to figure out how to add the modifier to my code. Could someone please throw me a bone and explain where I put this no_push(); Please.

It goes somewhere between line 50-68.

#include <boost/regex.hpp>
    #include <boost/filesystem/operations.hpp>
    #include <vector>
    #include <sstream>
    using namespace boost::filesystem;
    using namespace std;
     
    string srch_dir;
    string regx[10];
    string decision;
    int loop_counter=0;
    int x;
    ostringstream oss;
    vector<string> vec;
    int counter=0;
    string from_vec;
    string to_vec;
    int vec_check=0;
    const int BUFSIZE = 10000;
     
     
    /* VECTOR CONTENT CHECKER */
    void vec_el_check()
    { decision="";
    cout<< "Check vector status? y/n ";
    getline(cin, decision);
    while (decision !="n")
    {cout<< "Enter a vector element number\n";
    cin>> vec_check;
    cin.ignore();
    if (vec_check < counter)
    {cout <<"\n"<< vec[vec_check]<<" \n";}
    else cout << "Invalid vector element\n \n";
    cout << "Continue checking? y/n";
    getline(cin, decision);
    }
    }
     
     
    /* REMOVES QUOTATION MARKS FROM PATH LISTINGS */
    void dir_parse()
    { from_vec="";
    to_vec="";
    cout<<"Parse Loop Counter ["<<counter<<"]\n";
    std::string from_vec = vec[counter];
    std::string to_vec = from_vec.substr(1, from_vec.length() - 2);
    vec.at (counter) = to_vec;
    }
     
    /* LISTS ALL FILES IN A CHOSEN DIRECTORY */
    void initial_path( const path & directory, bool recurse_into_subdirs = true )
    { if(exists(directory))
    {directory_iterator end;
    for(directory_iterator iter(directory) ; iter != end; ++iter)
    if (is_directory( *iter ))
    {cout << iter->path() << " (directory)\n";
    if( recurse_into_subdirs ) initial_path(*iter);
    }
    else
    oss.str(""),
    cout<< "Path Loop Counter ["<<counter<<"}\n",
    oss << iter->path(),
    vec.push_back(oss.str()),
    cout<< vec[counter]<<"\n",
    dir_parse(),
    counter++;
    }
    }
     
    /* FINDS MULTIPLE CHARACTER PATTERNS IN LISTED FILES */
    /* FOR THE NUMBER OF FILES IN LIST, SEARCH THAT MANY FILES FROM VEC */
    /* DURING EACH FILE LOOP, LOOP FOR MULTIPLE SEARCH PATTERNS. */
    int reg()
    { for (int reg_counter=0; reg_counter < counter; reg_counter++)
    {for (int as=0; as < loop_counter; as++)
    {boost::regex re (regx[as]); /* SEARCH PATTERN */
    string file=vec[reg_counter];
    char buf[BUFSIZE];
    ifstream in(file.c_str());
    cout << "\n File "<<reg_counter<<":" <<file << "\n \n";
    if (in.is_open())
    {while (! in.eof() )
    {in.getline(buf, BUFSIZE-1);
    if (boost::regex_search(buf, re))
    {cout << buf << endl;}
    }
    in.close();
    }
    else cout << "Can't open file: "<< vec[reg_counter]<<"\n";
    }}
    return 0;
    }
     
     
    /* USER IMPUT AND PROGRAM DIRECTION */
    int main()
    { cout<< "Enter a Search Directory: ";
    getline(cin, srch_dir);
    decision = "y";
    do {
    cout<< "Enter a Search String: ";
    getline(cin, regx[loop_counter]) ;
    cout<< "Enter an Additional String? y/n ";
    getline(cin, decision);
    cout<< "Search Strings: "<<endl;
    for ( x=0; x<10; x++ )
    if (regx[x] != "")
    {cout << regx[x] << "\n";}
    loop_counter++;
    }
     
    while ( loop_counter < 10 & decision == "y" );
    cout << "Press enter to continue...";
    cin.get();
    initial_path( srch_dir ) ;
    cout << "----------------- \n \n";
    vec_el_check(); /* CHECK VECTOR CONTENTS */
    reg(); /* START REGEX SEARCH */
     
    return 0;
    }

I don't know that I know the exact answer, but the class "class recursive_directory_iterator " has a member function " void no_push(bool value=true) "

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.