have been working on this for a while now as I learn new things. This has kinda been my little project that I wanted to do alone for pride I suppose but I am getting so frustrated with it. When I run the program and search for a file in that same directory it will find the first file and it will spit an error out at me. Secondly if I try to search for a file in a sub directory it skips over it and tells me the search is completed without returning a file that I know is there. I believe that I am going about things in a wrong way in logic. I just got the Borland compiler where the find functions are different than in DevC++. Any help is greatly appreciated.
Code:
//Basic for right now
#include<dir.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 256
struct ffblk find;
main(int argc, char *argv[]){
int done;
char dir[MAX];
char *fin="Search completed\n";
if (argc<2){
printf("Usage: FIND <filename>\n");
exit(1);
}
done = findfirst( argv[1], &find, FA_NORMAL);
while (done != EOF){
int x=1,cd_done;
getcwd( dir, MAX);
strcat(dir,"\\");
strcat(dir, find.ff_name); //Attach forward slash to end of dir name
printf("%d) %s\n",x,dir);
if (find.ff_attrib == (FA_DIREC || _A_SUBDIR)) //check for directories in specified dir
{
chdir(find.ff_name);
cd_done = findfirst(argv[1],&find,FA_NORMAL);
if (cd_done == (-1))
printf("No files in %s\n",find.ff_name);
else
{
while (cd_done != EOF)
{
getcwd( dir, MAX);
strcat(dir, find.ff_name);
printf("%d) %s\n",x,dir);
cd_done = findnext(&find);
}
}
}
else
;
done = findnext(&find);
}
findclose(&find);
puts(fin);
return 0;
}