About File Find in win32 (iterator)
IntroductionSeveral times I worked with file names, I usually used Win32 API
such as ::FindFirstFile.. But it turns out that it's so boring work.
Finally, I realized I can use STL's great feature, iterator, to handle
file name iteration. That's why I made a simple STL iterator class for
file name iteration.
Usagewin32_file_iterator itBegin("c:\\*.*"), itEnd;
std::copy(itBegin, itEnd, ostream_iterator(cout, "\n"));
The code above shows the simplest way to use the class. Actually, you
can use almost all of STL algorithm, I think..
win32_file_iterator itBegin("c:\\*.*"), itEnd;
std::vector vec(itBegin, itEnd);
You also can fill the STL container by using the constructor that takes
begin iterator and end iterator.
Actually, win32_file_iterator class' constructor takes three parameters.
The first one is the filter string that is for calling ::FindFirstFile
function. Second one is the flag that specifies whether dereferenced path
is full path or not. For example, if it's true, the returned path string
is c:\test\aa.txt,otherwise it'll be aa.txt only. The last parameter is
the other flags which specify file attribute. For simplicity, I used Win32
API's FILE_ATTRIBUTE_XXX flags..
If you want to get only directory names, and which is full path, the code
will look like this:
win32_file_iterator itBegin("c:\\*", true, FILE_ATTRIBUTE_DIRECTORY);
So easy, huh?