Click here to Skip to main content
11,701,616 members (66,871 online)
Click here to Skip to main content
Add your own
alternative version

File and Directory Enumeration

, 3 Mar 2003 Ms-PL 156K 3.9K 61
Template based file and directory enumeration class.
#include <windows.h>
#include <tchar.h>
#include <conIO.H>

#pragma warning(push, 2)
#include <string>
#include <VECTOR>
using std::string;
using std::vector;
#pragma warning(pop)

#include "RecurseDir.h"

// derived class which implements a filter
class CTest : public CDirectoryContent
	explicit CTest(LPCTSTR pFilter) : m_filter(pFilter)

	virtual bool CheckUseFile (LPCTSTR , WIN32_FIND_DATA* pwfd ) 
		return ::PathMatchSpec(pwfd->cFileName, m_filter.c_str()) != FALSE;

	void dump()
		for(arraytype::iterator i = List().begin(); i != List().end(); ++i)
			cprintf(_T("%s\t%i bytes\n"), (*i).cFileName, (*i).nFileSizeLow);

	std::string m_filter;

int main(int argc, char* argv[])
	if(argc == 2)
		TCHAR	szCurrentDir[MAX_PATH];
		::GetCurrentDirectory(MAX_PATH, &szCurrentDir[0]);

		CTest	dir(argv[1]);

			cputs(_T("Run() failed"));

		cputs(_T("usage: RecurseDirText.exe filespec\n e.g.: RecurseDirTest.exe *.bmp"));

	// uncomment this to recursively delete the directory given as parameter 
	  CCleanDir rd;


	return 0;

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.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 4 Mar 2003
Article Copyright 2003 by Andreas S. Franci Gonçalves
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid