|
-
February 10th, 2008, 02:05 AM
#1
Traverse directory using boost library
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
-
February 11th, 2008, 10:56 AM
#2
Re: Traverse directory using boost library
It might be helpful to tell us which exception...
Did you try to run it in a debugger?
-
February 11th, 2008, 12:06 PM
#3
Re: Traverse directory using boost library
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.
- Alon
-
February 12th, 2008, 12:35 AM
#4
Re: Traverse directory using boost library
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);
}
}
}
-
February 12th, 2008, 10:14 AM
#5
Re: Traverse directory using boost library
Did you try to run it in a debugger?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|