home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / YAFF.ZIP / YAFF.C next >
C/C++ Source or Header  |  1992-09-11  |  5KB  |  174 lines

  1. /* yaff.c yet another file finder also y + my initials (aff)
  2.     Andrew Frantz CIS = 70712.3547
  3.     This file was originally made for DOS usage, this release 
  4.     incorportates HPFS long file names...Please subscribe to the 
  5.     Hackker Ethic ("Hacker" 1984 S. Levy) which calls for the 
  6.         1. post all source
  7.         2. enhance and learn from others source.
  8.         3. etc.
  9. */
  10. #include <stdio.h>
  11. #include <conio.h>
  12. #include <os2.h>
  13. #include <string.h>
  14.  
  15.  
  16. /*static FILEFINDBUF3  findBuffer  ;*/
  17. int findInSubs(char *), display(char *);
  18. static char input[13];
  19. int total = 0;
  20. long tbytes = 0;
  21. void dt_time(unsigned hour, char *dy);
  22. /*==================================================================*/
  23. int main(int argc, char *argv[])
  24. {
  25.     FILEFINDBUF3  findBuffer  ;
  26.     HDIR         findHandle  = 0xFFFFFFFF ;  /* Let OS/2 get us the handle */
  27.     int          findCount   = 1 ;
  28.     USHORT       rc ;
  29.     char         newPath[256], path[256], oldPath[256], path2[256];
  30.  
  31.     if(argc < 2)
  32.     {
  33.         printf("Command Line Syntax dserch filespec !!\n");
  34.       //    exit(0);
  35.     }
  36.     else
  37.         if(argc == 2)
  38.             strcpy(input,argv[1]);
  39.     strcpy(path,"\\");
  40.     printf("\n%20s\n\n","OS/2 File Search A. Frantz 1992");
  41.     strcpy(oldPath, path);
  42.     display((char *) &path);            /*find files arg under root*/
  43.     strcat(path, "*.*");
  44.  
  45. /*    DosFindFirst(PSZ    pszFileSpec,
  46.                                             PHDIR  phdir,
  47.                                             ULONG  flAttribute,
  48.                                             PVOID  pfindbuf,
  49.                                             ULONG  cbBuf,
  50.                                             PULONG pcFileNames,
  51.                                             ULONG  ulInfoLevel);
  52.  
  53.   */
  54.     if(rc = DosFindFirst(path ,&findHandle ,FILE_DIRECTORY  ,
  55.         &findBuffer , (ULONG)sizeof(findBuffer) , (PULONG)&findCount ,
  56.         (ULONG)0x0001))
  57.         return rc;
  58.     while(!rc)
  59.     {
  60.         if (strcmp(findBuffer.achName,".") && strcmp(findBuffer.achName,".."))
  61.         {
  62.             if (findBuffer.attrFile  == FILE_DIRECTORY )
  63.             {
  64.                 strcpy(path2, oldPath);
  65.                  strcat(path2 ,findBuffer.achName);
  66.                 display((char *) &path2);         /* prints all in this dir */
  67.                 findInSubs((char *) &path2);   /*check for argument in all subdirs*/
  68.             }
  69.         }
  70.         rc = DosFindNext(findHandle,
  71.                 &findBuffer,
  72.                 sizeof(findBuffer),
  73.                 (PULONG) &findCount);
  74.     }
  75.  
  76.     printf("\n\nTotal Files Found %d      Total byte Count %ld\n",total, tbytes);
  77. }
  78. /* ================================================================*/
  79. int findInSubs(char *dir)
  80. {
  81.     FILEFINDBUF3  findBuffer  ;
  82.  
  83.     HDIR         findHandle  = 0xFFFFFFFF ;  /* Let OS/2 get us the handle */
  84.     int          findCount   = 1 ;
  85.     USHORT       rc ;
  86.     char         newPath[256], path[256], new_dir[256];
  87.  
  88.     strcpy(new_dir, dir);
  89.     strcat(new_dir, "\\");
  90.     strcat(new_dir, "*.*");
  91.  
  92.     if(rc = DosFindFirst(new_dir ,&findHandle ,FILE_DIRECTORY  ,
  93.         &findBuffer , (ULONG)sizeof(findBuffer) , (PULONG)&findCount ,
  94.         (ULONG)0x0001))
  95.         return rc;
  96.  
  97.     while(!rc)
  98.     {
  99.         if (strcmp(findBuffer.achName,".") && strcmp(findBuffer.achName,".."))
  100.         {
  101.             if (findBuffer.attrFile  == FILE_DIRECTORY )
  102.             {
  103.                 strcpy(path, dir);
  104.                 strcat(path,"\\");
  105.                  strcat(path ,findBuffer.achName);
  106.                 display((char *) &path);
  107.                 findInSubs((char *) &path);       /*recursize step*/
  108.             }
  109.         }
  110.         rc = DosFindNext(findHandle,
  111.             &findBuffer,
  112.             sizeof(findBuffer),
  113.             (PULONG) &findCount);
  114.     }
  115. }
  116. /*===================================================================*/
  117. int display(char *path2)
  118. {
  119.     HDIR         findHandle  = 0xFFFFFFFF ;  /* Let OS/2 get us the handle */
  120.     int          findCount   = 1 ;
  121.     USHORT       rc ;
  122.     FILEFINDBUF3  findBuffer  ;
  123.  
  124. /*    USHORT day , mon, year, hour , min;*/
  125.     char *blank[] = {"        "}, dy[3];
  126.     char path[256];
  127.  
  128.     strcpy(dy, "   ");
  129.     strcpy(path, path2);
  130.     strcat(path, "\\");
  131.     strcat(path, input);
  132.     
  133.     if(rc = DosFindFirst(path ,&findHandle ,0 ,
  134.         &findBuffer , (ULONG)sizeof(findBuffer) , (PULONG)&findCount ,
  135.         (ULONG)0x0001))
  136.     {
  137.         return rc;
  138.     }
  139.  
  140.     printf("%s\n", path2);
  141.     while(!rc)    {
  142.         if (findBuffer.attrFile  != FILE_DIRECTORY )
  143.         {
  144.             dt_time(findBuffer.ftimeLastWrite.hours, dy);
  145.             printf("%s%-14s%12ld bytes ",blank[0], findBuffer.achName, findBuffer.cbFileAlloc);
  146.  
  147.             printf("%02u/%02d/%02d %02d:%02d%s\n",
  148.                   findBuffer.fdateLastWrite.month,
  149.                   findBuffer.fdateLastWrite.day ,
  150.                   findBuffer.fdateLastWrite.year+80,
  151.                   findBuffer.ftimeLastWrite.hours,
  152.                   findBuffer.ftimeLastWrite.minutes, dy);
  153.             total++;
  154.             tbytes += findBuffer.cbFileAlloc;
  155.         }
  156.         rc = DosFindNext(findHandle,
  157.             &findBuffer,
  158.             sizeof(findBuffer),
  159.             (PULONG) &findCount);
  160.     }
  161. }
  162.  
  163. /*===================================================================*/
  164. void dt_time(unsigned hour, char *dy)
  165. {
  166.     if(hour == 0)
  167.         hour += 12;
  168.     if(hour >= 12)
  169.         strcpy(dy,"pm");
  170.     else
  171.         strcpy(dy, "am");
  172. }
  173. /*===================================================================*/
  174.