Click to See Complete Forum and Search --> : Traverse directory using boost library


oalfishcivil
February 10th, 2008, 01:05 AM
I am using boost filesystem library to traverse directory. The function I wrote is to search a file in a directory and all its subdirectories.
I am using the following code to traverse the directory.
directory_iterator iter(dir_path), end_iter;
for(; iter!= end_iter; ++iter)

For most of the directories, this works beautifully. But when I try to search c:\
The program terminates with exception.
Anybody knowing what is the problem and how to avoid that?
Thanks

Marc G
February 11th, 2008, 09:56 AM
It might be helpful to tell us which exception...
Did you try to run it in a debugger?

Hermit
February 11th, 2008, 11:06 AM
Does C:\ appear in a string literal? If so, have you properly escaped the backslash (like "C:\\")?

A small, compilable example which produces the error would be helpful.

oalfishcivil
February 11th, 2008, 11:35 PM
I don't really know what the exception is. It just says the program terminates.
The program works fine for most of the cases. Seems that when it meets some particular file in the c drive which cause the program to terminate. Very strange.

Here is the function
void find_file(const path & dir_path, const string & file_name, vector<path> & pfound)
{
if( !exists(dir_path) || !is_directory(dir_path) )
return ;
directory_iterator iter(dir_path), end_iter;
for(; iter!= end_iter; ++iter)
{
if( is_directory(*iter) )
{
find_file(*iter, file_name, pfound);
}
else if( wildcmp( file_name,iter->leaf())==1)//compare the file name to //see if they are the same. This supports wildcards
{
pfound.push_back( *iter);
}
}
}

Marc G
February 12th, 2008, 09:14 AM
Did you try to run it in a debugger?