home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / SWITCH2.ZIP / FF.C next >
C/C++ Source or Header  |  1990-01-22  |  2KB  |  94 lines

  1. /* ff.c */
  2. /* adapted from p.175 Adv. OS/2 Programming  by Ray Duncan */
  3.  
  4. #include <os2.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <dos.h>
  8.  
  9. FILEFINDBUF sbuf;
  10.  
  11. int drvno;
  12. int count = 0;
  13. char sname[256];
  14. main(argc,argv)
  15. int argc;
  16. char **argv;
  17. {
  18. unsigned long drvmap;
  19.  
  20.     if(argc < 2)
  21.         {
  22.         printf("findfile: missing filename\n");
  23.         exit(1);
  24.         }
  25.     DosQCurDisk(&drvno, &drvmap);
  26.     if(((strlen(argv[1])) >=2) && ((argv[1])[1] == ':'))
  27.     {
  28.         drvno = ((argv[1])[0] | 0x20) - ('a'-1);
  29.  
  30.         if(DosSelectDisk(drvno))
  31.         {
  32.             printf("\nfindfile:bad drive\n");
  33.             exit(1);
  34.         }
  35.         argv[1] += 2;
  36.     }
  37.     strcpy(sname,argv[1]);
  38.     schdir("\\");
  39.     if(count == 0) 
  40.         printf("\n\nfindfile: no files\n");
  41.     else
  42.         printf("\n\n%d file(s) found\n",count);
  43. }
  44.  
  45. schdir(char *dirname)
  46. {
  47.     unsigned shan = -1;
  48.     int scnt = 1;
  49.     DosChdir(dirname, 0L);
  50.     schfile();
  51.     if(!DosFindFirst("*.*",&shan,_A_NORMAL | _A_SUBDIR,
  52.         &sbuf,sizeof(sbuf),&scnt,0L))
  53.     {
  54.         do
  55.         {
  56.             if((sbuf.attrFile & _A_SUBDIR) && (sbuf.achName[0] != '.'))
  57.             {
  58.                 schdir(sbuf.achName);
  59.                 DosChdir("..",0L);
  60.             }
  61.         }while(DosFindNext(shan,&sbuf,sizeof(sbuf),&scnt) == 0);
  62.     }
  63.     DosFindClose(shan);
  64. }
  65. schfile()
  66. {
  67.     unsigned shan = -1;
  68.     int scnt = 1;
  69.     if(!DosFindFirst(sname,&shan,_A_NORMAL,&sbuf,sizeof(sbuf),&scnt,0L))
  70.     {
  71.         do pfile();
  72.         while(DosFindNext(shan,&sbuf,sizeof(sbuf),&scnt)==0);
  73.     }
  74.     DosFindClose(shan);
  75. }
  76. pfile()
  77. {
  78.     count++;
  79.     pdir();
  80.     printf("%s",strlwr(sbuf.achName));
  81. }
  82. pdir()
  83. {
  84.     char dbuf[80];
  85.     int dlen=sizeof(dbuf);
  86.     DosQCurDir(0,dbuf,&dlen);
  87.     if(strlen(dbuf) != 0) 
  88.         strcat(dbuf,"\\");
  89.     printf("\n%c:\\%s",drvno+'a'-1,strlwr(dbuf));
  90. }
  91.  
  92.     
  93.  
  94.