I've wandered through this thread, an FAQ, and another recent post, and slammed something together that looks for .mp3 files up to MAXLEVEL directories deep from the starting directory. It's done in Borland on a Windows box; it seems to find such files on my system.
Could this be anything similar to what you are trying to do? (Some of my guesses are off the mark, however.)
Code:
#include <stdio.h>
#include <dir.h>
#include <string.h>
#include <dos.h> /* for FA_DIREC and FA_ARCH */
#define MAXLEVEL 3
#define ALL_ATTS (FA_DIREC | FA_ARCH)
int strend(const char *s, const char *t)
{
size_t slen = strlen(s);
size_t tlen = strlen(t);
int rc;
if ( slen < tlen )
rc = 0;
else if ( strcmp(s + (slen - tlen), t) == 0 )
rc = 1;
else
rc = 0;
return rc;
}
#ifdef MAXLEVEL
int maxlevel = 0;
#endif
void walker(const char *path, const char *findme)
{
struct ffblk finder;
unsigned int res;
#ifdef MAXLEVEL
if(++maxlevel > MAXLEVEL)
{
return;
}
#endif
chdir(path);
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, findme);
chdir("..");
--maxlevel;
}
else
{
if ( strend(finder.ff_name, findme) )
{
printf("%s\\%s\n", path, finder.ff_name);
fflush(stdout);
}
}
}
}
int main(void)
{
walker("c:\\Program Files", ".mp3");
return(0);
}
[EDIT]Salem, vVv and Hammer (FAQ), Prelude, me.