How to set a search mask with wild card for directory_iterator ?

Hi all! I'm trying to learn how to use boost and for a first exercise I chose to create a class to perform files enumeration. The code below works fine but I didn't find a way to set a search mask with wild card, example: *.jpeg or test???.* How can I do it? //------------------------------------------------------------------- VOID CFileSearch::InternalSearch( path RootDir, string Mask ) { directory_iterator EndDirItr; string OutPut; for ( directory_iterator DirItr( RootDir ); DirItr != EndDirItr; ++DirItr ) { if ( is_regular( DirItr->status() ) ) { m_FileCount++; OutPut = "FILE: " + DirItr->path().string(); _tprintf( _T( "%s\n" ), OutPut.c_str() ); } else { InternalSearch( DirItr->path(), Mask ); } } } //------------------------------------------------------------------- VOID CFileSearch::Search( string RootDir, string Mask ) { path TempRootDir = system_complete( path( RootDir, native ) ); if ( exists( TempRootDir ) == true ) { InternalSearch( TempRootDir, Mask ); _tprintf( _T( "%d files found\n" ), m_FileCount ); } }

Silvio,
you have to implement it yourself. You could use a boost regular expression
lib or xpressive lib, to match mask(s) with file names found. I would
suggest to take a look at boost iterator lib. Using the regex to match the
mask + wrapping the directory_iterator into filetered_iterator will do the
job.
Best Regards,
Ovanes
On Tue, Apr 1, 2008 at 6:25 PM, Silvio Reis Junior
Hi all! I'm trying to learn how to use boost and for a first exercise I chose to create a class to perform files enumeration. The code below works fine but I didn't find a way to set a search mask with wild card, example: *.jpeg or test???.* How can I do it?
//------------------------------------------------------------------- VOID CFileSearch::InternalSearch( path RootDir, string Mask ) { directory_iterator EndDirItr; string OutPut; for ( directory_iterator DirItr( RootDir ); DirItr != EndDirItr; ++DirItr ) { if ( is_regular( DirItr->status() ) ) { m_FileCount++; OutPut = "FILE: " + DirItr->path().string(); _tprintf( _T( "%s\n" ), OutPut.c_str() ); } else { InternalSearch( DirItr->path(), Mask ); } } }
//------------------------------------------------------------------- VOID CFileSearch::Search( string RootDir, string Mask ) { path TempRootDir = system_complete( path( RootDir, native ) ); if ( exists( TempRootDir ) == true ) { InternalSearch( TempRootDir, Mask ); _tprintf( _T( "%d files found\n" ), m_FileCount ); } }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi Ovanes!
Thanks for the explanation. I'll try it.
On Tue, Apr 1, 2008 at 4:42 PM, Ovanes Markarian
Silvio,
you have to implement it yourself. You could use a boost regular expression lib or xpressive lib, to match mask(s) with file names found. I would suggest to take a look at boost iterator lib. Using the regex to match the mask + wrapping the directory_iterator into filetered_iterator will do the job.
Best Regards, Ovanes
On Tue, Apr 1, 2008 at 6:25 PM, Silvio Reis Junior
wrote: Hi all! I'm trying to learn how to use boost and for a first exercise I chose to create a class to perform files enumeration. The code below works fine but I didn't find a way to set a search mask with wild card, example: *.jpeg or test???.* How can I do it?
//------------------------------------------------------------------- VOID CFileSearch::InternalSearch( path RootDir, string Mask ) { directory_iterator EndDirItr; string OutPut; for ( directory_iterator DirItr( RootDir ); DirItr != EndDirItr; ++DirItr ) { if ( is_regular( DirItr->status() ) ) { m_FileCount++; OutPut = "FILE: " + DirItr->path().string(); _tprintf( _T( "%s\n" ), OutPut.c_str() ); } else { InternalSearch( DirItr->path(), Mask ); } } }
//------------------------------------------------------------------- VOID CFileSearch::Search( string RootDir, string Mask ) { path TempRootDir = system_complete( path( RootDir, native ) ); if ( exists( TempRootDir ) == true ) { InternalSearch( TempRootDir, Mask ); _tprintf( _T( "%d files found\n" ), m_FileCount ); } }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I have find promising (depreciated) library in cregex.hpp. (If you are to try it yourself, make sure you have few .jpg files in 'jnk' directory). I have tried experimenting setting different boost::match_flag_type but no luck. Also I didn't receive any callback as expected in my 'cb' callback func? The program would seem to find all files, but then it will crash in bool regex_search(…). Any ideas? #include "boost/regex/v4/cregex.hpp" bool cb(const char* file) { return true; } int _tmain(int argc, _TCHAR* argv[]) { boost::RegEx regEx; std::string files ("C:\\jnk\\*.jpg"); regEx.FindFiles(cb, files, true); return 1; }
participants (3)
-
Novi Sad
-
Ovanes Markarian
-
Silvio Reis Junior