That's not enough information to help: give the complete source code and the compiler error. Here's that boost tutorial compiled live, online: http://liveworkspace.org/code/a342716e139beb575b0a7d725c45175a (I only hard-coded the directory it's searching since LWS doesn't allow input)
I have a problem: I'm creating a function to search through all directories, and it will be designed to return a vector<string> of all the matching directories it finds. It will only use a single string, such as "minecraft", or "users", and search your computer until it finds any directory with that string anywhere in its' name.
I'm having problems converting boost::filesystem::directory_entry variables into string variables for this operation. Is there any way to convert a directory entry into a string?
It looks like either will work, I initially thought directory_entry didn't have a string method.
Edit: I'm not particularly experienced with boost so I dont know which would be recommended.
I am having problems. I created a recursive algorithm to search every file/folder on the disk drive for specific keywords in the folder/file names. It works, but (it seems) every time a match is found, and recursively returned, it crashes. I dont have the debugger (i installed boost + minGW and it didnt come with a Debugger... :\ ) so I'm kind of clueless. I did insert some test code (display variables, etc...) and it all points to the recursively returned values. I don't know why It is crashing. Can someone help me out? Here is the recursive algorithm I wrote:
vector<string> find_dir(string f_name = "", string path = "")
{
vector<boost::filesystem::directory_entry> directories;
vector<string> rec_matches;
vector<string> matching_directories;
if(keypressed() == true)
{
return matching_directories;
}
string s; //for string operations
boost::filesystem::directory_entry directory_entry_to_string;
boost::filesystem::path p;
p = path;
if(path == "") //default it
{
p = "C:\\";
}
copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(directories));
if(directories.size() > 0) //just a precaution
{
if(match(directories, f_name) == true) //check to see if there is a match
{
for(unsignedint x = 0; x < directories.size(); x++) //there us a match, add the matching dirs to a vector
{
directory_entry_to_string = directories[x];
s.clear();
s = directory_entry_to_string.path().string();
if(s_match(s, f_name) == true)
{
matching_directories.push_back(s);
}
}
}
}
//now we go deeper into the filesystem...
for(unsignedint x = 0; x < directories.size(); x++)
{
p = directories[x].path();
if((is_matching_dir(directories[x], matching_directories) == false) && (dir(p) == true)) //making sure we dont add another of the same directory...
{
rec_matches.clear();
rec_matches = find_dir(f_name, p.string());
if(rec_matches.size() > 0)
{
for(unsignedint y = 0; y < rec_matches.size(); x++)
{
matching_directories.push_back(rec_matches[x]); // crashes HERE when rec_matches.size() > 1, and of course i cant figure out why...
}
}
}
}
return matching_directories;
}
I would really appreciate any help you can give. I know it is in this function, because it always crashes in this function.