By the way, Salem posted an excellent example some time back. Do a search on the boards to find it...
...Here it is. One thing though, it needed a slight revision...
Code:
//...Author: Salem A.K.A. "stee"
#include <stdio.h>
#include <dir.h>
#include <string.h>
#define ALL_ATTS ( \
FA_DIREC | \
FA_ARCH )
void walker ( char *path ) {
struct ffblk finder;
unsigned int res;
chdir(path); //...added this so you don't crash...
for ( res = findfirst ( "*.*", &finder, ALL_ATTS );
res == 0;
res = findnext( &finder ) ) {
if ( strcmp(finder.ff_name, ".") == 0 ) continue; // current dir
if ( strcmp(finder.ff_name, "..") == 0 ) continue; // parent dir
// if its a directory, examine it
// else compare the filename with the one we're looking for
if ( finder.ff_attrib & FA_DIREC ) {
char newpath[MAXPATH];
strcpy( newpath, path );
strcat( newpath, "\\" );
strcat( newpath, finder.ff_name);
chdir( finder.ff_name );
walker( newpath );
chdir( ".." );
} else {
if ( strcmp( finder.ff_name, "words.txt" ) == 0 ) {
printf( "Found!!!" );
}
}
}
}
int main ( ) {
char *root = "\\";
chdir( root );
walker( root );
return 0;
}
To make it fit your needs, just add another parameter to the function...Tho now that I think about it, this looks a little incomplete...still, try it.