Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

File and Directory Enumeration

, 3 Mar 2003 Ms-PL
Template based file and directory enumeration class.
recursedir_demo.zip
RecurseDirTest.dsp
RecurseDirTest.dsw
recursedir_src.zip
#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
{
public:
	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);
	}

private:
	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]);

		if(dir.Run(szCurrentDir))
			dir.dump();
		else
			cputs(_T("Run() failed"));

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

	//
	// uncomment this to recursively delete the directory given as parameter 
	//
	/*
	
	  CCleanDir rd;
	  rd.Run(argv[1]);

	*/

	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.

License

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

Share

About the Author

No Biography provided

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