#include #include #include #include #include #define MAX_PATH 256 void WalkTree(const char *path, void (*Proc)(const char *)) { int result = 0; long handle; struct _finddata_t finfo; char searchPath[MAX_PATH], nextFile[MAX_PATH]; sprintf(searchPath, "%s\\*.*", path); handle= _findfirst(searchPath, &finfo); while (!result) { if (!strcmp(finfo.name, ".")) { _findnext(handle,&finfo); result = _findnext(handle, &finfo); continue; } sprintf(nextFile, "%s\\%s", path, finfo.name); Proc(nextFile); if (finfo.attrib & _A_SUBDIR) WalkTree(nextFile, Proc); result = _findnext(handle, &finfo); } } void DirTree(const char *path, void (*Proc)(const char *)) { char correctPath[MAX_PATH]; int lastIndex; if (*path == '\0') return; strcpy(correctPath, path); lastIndex = strlen(path) - 1; if (path[lastIndex] == '\\' || path[lastIndex] == '/' || path[lastIndex] == ':') correctPath[lastIndex] = '\0'; WalkTree(correctPath, Proc); } void Disp(const char *path) { puts(path); } int main() { DirTree("\\mp3", Disp); return 0; }