home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1992
/
04
/
findfile.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-05
|
3KB
|
83 lines
// findfile.cpp RHS 7/18/91
#include<conio.h>
#include"findfile.h"
FindFile::FindFile(char *filename, unsigned type)
{
notfound = (findfirst(filename,&F,type) ? TRUE : FALSE);
nomore = (strchr(filename,'*') || strchr(filename,'?')) ? FALSE : TRUE;
}
int FindFile::FindNext(void)
{
if(nomore)
return FALSE;
return !(nomore = notfound = (findnext(&F) ? TRUE : FALSE));
}
BOOL RecursiveFileFind::rff(char *dirspec, char *filespec)
{
char *q, *r, old;
int done;
BOOL retval = FALSE;
struct ffblk findbuf;
// r = &(Lastchar(dirspec)); // save address of
r = &dirspec[strlen(dirspec)-1]; // save address of
r++; // NULL at end of dirspec
if(Lastchar(dirspec) != '\\') // add trailing backslash
strcat(dirspec,"\\");
q = &dirspec[strlen(dirspec)-1];
// q = &(Lastchar(dirspec));
q++; // set pointer to end
strcat(dirspec,filespec); // add filespec to dirspec
done = findfirst(dirspec,&findbuf,ALL_FILES);// find only files
while(!done)
{
old = *q; // save off character @ q
*q = '\0'; // stuff in a NULL
PostResults(dirspec,&findbuf);
*q = old; // restore character @ q
if(keycheck && kbhit())
{
if(eatkey)
getch();
retval = TRUE;
goto terminate;
}
done = findnext(&findbuf); // get next filename
}
strcpy(q,"*.*"); // work through sub-dirs
done = findfirst(dirspec,&findbuf,FA_DIREC);// find subdirectories
while(!done)
{
if(findbuf.ff_name[0] != '.' && (findbuf.ff_attrib & FA_DIREC))
{
strcpy(q,findbuf.ff_name); // set up with sub-dir name
if(retval = rff(dirspec,filespec)) // recurse into sub-dir
goto terminate;
strcpy(q,"*.*"); // restore dirspec
}
if(keycheck && kbhit())
{
if(eatkey)
getch();
retval = TRUE;
goto terminate;
}
done = findnext(&findbuf);
}
terminate:
*r = '\0'; // restore to original state
return retval;
}