Click here to Skip to main content
12,246,754 members (54,683 online)
Click here to Skip to main content

Stats

42K views
369 downloads
17 bookmarked
Posted

Win32 File Name Iteration Boost Way

, 3 Nov 2005 CPOL
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)

Share

About the Author

mb2sync
Japan Japan
I am worried about my poor English...

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 4 Nov 2005
Article Copyright 2005 by mb2sync
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid