This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.


  File Enumerator
  Submitted by

The following code lists all the files in a directory, and allows you to set a callback for each new file or directory that is found. The _directory_ parameter should be provided with a directory name plus wildcard (i.e. "/stuff/*.*"). Set recurse to true if you want to search subdirectories.

Sam McGrath

Download Associated File: fenumerate.cpp (965 bytes)

//Editor's note:  
//COTD Entry:  File Enumerator by Sam McGrath []

void System_Dir(const char *directory, bool recurse, void(*dirCallback)(const char *dir), void(*fileCallback)(const char *filename)) { WIN32_FIND_DATA finddata; HANDLE handle;

handle = FindFirstFile(directory, &finddata);

if (handle == INVALID_HANDLE_VALUE) return;

do { if (!(finddata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) && !(finddata.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(finddata.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)) { if (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (strcmp(finddata.cFileName, ".") && strcmp(finddata.cFileName, "..")) if (dirCallback) dirCallback(finddata.cFileName); } else { if (fileCallback) fileCallback(finddata.cFileName); } } } while (FindNextFile(handle, &finddata));

FindClose(handle); }

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.


Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.