Wanna know if this is a good Recursive function
Code:
int Recurse(char *argv) //recursion is a joy
{
FILEINFO FileName; //remember I defined _finddata_t as FILEINFO up at the top
long lFileHandle = 0;
int nDone = 0;
long nNumFiles = 0;
int nCount = 0;
char FilePathBuffer[256];
char WildCard[] = "\\*.*";
const char IdxWildCard[] = "*.IDX";
char FileNameBuffer[101][10] = {0};
bool bCheckedDir = false;
while(argv[nCount] != '*') //find '*' and omit it
{
FilePathBuffer[nCount] = argv[nCount]; //copy to FilePathBuffer so I have an uncorrupted copy for the filepath
nCount++; //count for later use with catenation
}
FilePathBuffer[nCount] = '\0'; //cantenate
lFileHandle = _findfirst(argv, &FileName); //retrieve first file and a handle to the files
while(!lFileHandle || !nDone)
{
nNumFiles++;
if(FileName.name[0] != '.')
{
nNumFilesTotal++;
}
if(!bCheckedDir)
{
strncat(FilePathBuffer, IdxWildCard, 10);
GetFileNames(FilePathBuffer, FileNameBuffer);
GetPathName(FilePathBuffer, FileNameBuffer);
FilePathBuffer[nCount] = '\0';
bCheckedDir = true;
}
if((FileName.attrib == 16 || FileName.attrib == 17 || FileName.attrib == 18 || FileName.attrib == 2066) && FileName.name[0] != '.')
{
strncat(FilePathBuffer, FileName.name, strlen(FileName.name));
strncat(FilePathBuffer, WildCard, strlen(WildCard));
Recurse(FilePathBuffer);
FilePathBuffer[nCount] = '\0';
}
nDone = _findnext(lFileHandle, &FileName);
}
return 0;
}