home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 8957 < prev    next >
Encoding:
Text File  |  1992-09-01  |  2.7 KB  |  103 lines

  1. Path: sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!hal.gnu.ai.mit.edu!rwed
  2. From: rwed@hal.gnu.ai.mit.edu (N7YVM)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: WANTED: Code to search DOS directory/subdirectories
  5. Message-ID: <27442@life.ai.mit.edu>
  6. Date: 1 Sep 92 17:56:31 GMT
  7. References: <1992Aug27.044445.22165@uwm.edu> <BtMqnB.9J0@mentor.cc.purdue.edu>
  8. Sender: news@ai.mit.edu
  9. Distribution: comp.os.msdos.programmer
  10. Organization: /etc/organization
  11. Lines: 90
  12.  
  13. Heres a little bit of code I wrote to search dir trees for file specs... Its worked well for quite a while...
  14. I used to use norton for this, but it (norton ff) doesnt work well over a CTTY COM1 link...
  15. Theres no bells or whistles, but I want to throw in a filesize and attrib report one day when Im not in
  16. such a rush...
  17.  
  18.  
  19. #include <alloc.h>
  20. #include <fcntl.h>
  21. #include <string.h>
  22. #include <io.h>
  23. #include <dir.h>
  24. #include <dos.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include "filefind.h"
  28.  
  29. const fattrib=FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH;
  30. const dattrib=FA_DIREC;
  31.  
  32. char currdir[200];
  33.  
  34. void process_dir(char *pspec,char *mname,char *mext,struct ffblk *ffblock) {
  35. char drive[10], *dir, *name, ext[8], *path;
  36.   dir=(char *)malloc(200);
  37.   name=(char *)malloc(20);
  38.   path=(char *)malloc(300);
  39.   if ( (ffblock->ff_attrib&(FA_DIREC)) &&
  40.        (ffblock->ff_name[0]!='.')      ) {
  41.     fnsplit(pspec,drive,dir,name,ext);
  42.     strcat(dir,ffblock->ff_name);
  43.     strcat(dir,"\\");
  44.     strcpy(currdir,dir);
  45.     fnmerge(path,drive,dir,mname,mext);
  46.     filefind(path);
  47.     }
  48.   free(dir);
  49.   free(name);
  50.   free(path);
  51.   }
  52.  
  53. void filefind(char *spec) {
  54. char drive[10], *dir,*name, ext[8], *pspec;
  55. struct ffblk *ffblock;
  56.  
  57.   ffblock=(struct ffblk *)malloc(sizeof(struct ffblk));
  58.   dir=(char *)malloc(200);
  59.   name=(char *)malloc(20);
  60.   pspec=(char *)malloc(300);
  61.  
  62.   fnsplit(spec,drive,dir,name,ext);
  63.   fnmerge(currdir,drive,dir,"","");
  64.  
  65.   if (0==findfirst(spec,ffblock,fattrib)) {
  66.     printf("file: %s%s \n",currdir,ffblock->ff_name);
  67.     while (0==findnext(ffblock)) printf("file: %s%s \n",currdir,ffblock->ff_name);
  68.     }
  69.  
  70.   fnmerge(pspec,drive,dir,"*",".*");
  71.  
  72.   if (0==findfirst(pspec,ffblock,dattrib)) {
  73.     process_dir(pspec,name,ext,ffblock);
  74.     while (0==findnext(ffblock)) process_dir(pspec,name,ext,ffblock);
  75.     }
  76.  
  77.   free(dir);
  78.   free(name);
  79.   free(pspec);
  80.   free(ffblock);
  81.  
  82.   }
  83.  
  84.  
  85. int main(int argc, char *argv[]) {
  86.  
  87.   if (argc<2) {
  88.     puts(" ");
  89.     puts("File finder: ");
  90.     puts("This utility searches the directory structure, starting");
  91.     puts(" at the current or specified dir for a file spec (wild cards valid)");
  92.     puts(" ");
  93.     puts("Example:  filefind *.c");
  94.     exit(1);
  95.     }
  96.  
  97.   printf("Searching for %s...\n",argv[1]);
  98.  
  99.   filefind(argv[1]);
  100.  
  101.   return 0;
  102.   }
  103.