Click here to Skip to main content
15,884,793 members
Articles / Desktop Programming / MFC

Win32 File Name Iteration Boost Way

Rate me:
Please Sign up or sign in to vote.
4.71/5 (10 votes)
3 Nov 2005CPOL2 min read 56.9K   397   17  
A Port of ::FindFirstFile to Boost.Range and Boost.Foreach
#pragma once

#include <functional>

namespace find_file {

template< DWORD attr >
struct find_file_matches_mask :
	std::unary_function<WIN32_FIND_DATA, bool>
{
	bool operator()(WIN32_FIND_DATA const& data) const
	{
		return (data.dwFileAttributes & attr) != 0;
	}
};

struct find_file_is_read_only :
	find_file_matches_mask<FILE_ATTRIBUTE_READONLY>
{ };

struct find_file_is_directory :
	find_file_matches_mask<FILE_ATTRIBUTE_DIRECTORY>
{ };

struct find_file_is_compressed :
	find_file_matches_mask<FILE_ATTRIBUTE_COMPRESSED>
{ };

struct find_file_is_system :
	find_file_matches_mask<FILE_ATTRIBUTE_SYSTEM>
{ };

struct find_file_is_hidden :
	find_file_matches_mask<FILE_ATTRIBUTE_HIDDEN>
{ };

struct find_file_is_temporary :
	find_file_matches_mask<FILE_ATTRIBUTE_TEMPORARY>
{ };

struct find_file_is_normal :
	find_file_matches_mask<FILE_ATTRIBUTE_NORMAL>
{ };

struct find_file_is_archived :
	find_file_matches_mask<FILE_ATTRIBUTE_ARCHIVE>
{ };

struct find_file_is_dots :
	std::unary_function<WIN32_FIND_DATA, bool>
{
	bool operator()(WIN32_FIND_DATA const& data) const
	{
		return
			find_file_is_directory()(data) &&
			data.cFileName[0] == _T('.') &&
			(
				data.cFileName[1] == _T('\0') ||
				(
					data.cFileName[1] == _T('.') && 
					data.cFileName[2] == _T('\0')
				)
			)
		;
	}
};

} // namespace find_file

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Japan Japan
I am worried about my poor English...

Comments and Discussions