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

  1. //
  2. //  LD.C
  3. //
  4. //  List Date - OS/2 directory lister, lists all 3 dates in an
  5. //  HPFS volume.
  6. //
  7. //  This program requires the MS Presentation Manager toolkit, version
  8. //  1.1 or later, to compile. It could easily be made to compile without
  9. //  this toolkit simply by supplying your own prototypes for DosFindFirst()
  10. //  and DosFindNext(). You would also need to recreate the _FILEFINDBUF
  11. //  structure.
  12. //
  13. //  Chris Boaro   18-Jan-90   Initial Coding
  14. //
  15.  
  16. #define  INCL_DOSERRORS
  17. #include <os2.h>
  18.  
  19. #include <stdio.h>
  20.  
  21.  
  22. char *addcomma(long, char *, int);
  23.  
  24.  
  25. main(int argc, char *argv[])
  26. {
  27.    int rc, a;
  28.    char     temp[80], temp2[30];
  29.    long     dirsize;
  30.    struct   _FILEFINDBUF findbuff;
  31.    unsigned short handle = 0xffff;
  32.    unsigned short count = 1;
  33.  
  34.    if( argc > 1 )
  35.       strcpy(temp,argv[1]);
  36.    else
  37.       strcpy(temp,"*.*");
  38.  
  39.    count = 1; a=0; dirsize = 0L;
  40.    handle = 0xffff;
  41.    rc = DosFindFirst(temp,&handle,0,&findbuff,sizeof(findbuff),&count,0L);
  42.    if( rc == ERROR_NO_MORE_FILES )
  43.       printf("\n\rNo files found\n\r");
  44.    else if( rc == 0 ) 
  45.       printf("\n\rDirectory for %s\n\r\n\r",temp);
  46.    while( rc == 0 ) {
  47.       a++;      /* file count */
  48.       dirsize += findbuff.cbFile;
  49.       #define FDLW  findbuff.fdateLastWrite
  50.       #define TMLW  findbuff.ftimeLastWrite
  51.       #define FDCR  findbuff.fdateCreation
  52.       #define TMCR  findbuff.ftimeCreation
  53.       #define FDAC  findbuff.fdateLastAccess
  54.       #define TMAC  findbuff.ftimeLastAccess
  55.       if( a == 1 ) 
  56.          printf("                          Created         Last Write      Last Access\n");
  57.       addcomma(findbuff.cbFile,temp,10);
  58.       printf("%-12s  %10s  %2d-%02d-%2d %2d:%02d  %2d-%02d-%2d %2d:%02d  %2d-%02d-%2d %2d:%02d\n\r",findbuff.achName,temp,
  59.              FDCR.month,FDCR.day,FDCR.year+80,
  60.              TMCR.hours,TMCR.minutes,
  61.              FDLW.month,FDLW.day,FDLW.year+80,
  62.              TMLW.hours,TMLW.minutes,
  63.              FDAC.month,FDAC.day,FDAC.year+80,
  64.              TMAC.hours,TMAC.minutes);
  65.       rc = DosFindNext(handle,&findbuff,sizeof(findbuff),&count);
  66.    }
  67.    if( a ) {
  68.       addcomma((long)a,temp,20);
  69.       addcomma(dirsize,temp2,20);
  70.       printf("\n\r   %s file%s found, using %s bytes of disk space\n\r",temp,a==1?"":"s",temp2);
  71.    }
  72.    else
  73.       printf("\n\rNo matching files found\n\r");
  74.    return(0);
  75. }
  76.  
  77.  
  78. //
  79. //  addcomma()
  80. //
  81. //  Operates similar to ltoa() except that commas are inserted in the
  82. //  correct places in the number. If the resultant string is greater
  83. //  then 'maxlen', an 'E' appears in the last digit.
  84. //
  85. char *addcomma(long inb, char *outst, int maxlen)
  86. {
  87.    char tmp[20], tmp2[25], *p;
  88.    int  numc, len, chsf=0, i;
  89.  
  90.    ltoa(inb,tmp,10);
  91.    len = strlen(tmp);
  92.    numc = (len - 1) / 3;                 // get number of commas
  93.    if( (inb < 0) && ((len) % 3 == 1) )   // check for negative numbers
  94.       numc--;
  95.    p = &tmp2[24];
  96.    *(p--) = '\0';
  97.    while( len ) {                        // while there are chars to add
  98.       if( (chsf == 3) && numc ) {        // if chars added is 3 and still need more commas
  99.          *(p--) = ',';
  100.          chsf = 0;
  101.          numc--;
  102.       }
  103.       else {                             // otherwise, just add the char
  104.          *(p--) = tmp[(len--)-1];
  105.          chsf++;
  106.       }
  107.    }
  108.    p++;
  109.    len = strlen(p);                      // check the end string len
  110.    if( len > maxlen ) {
  111.       *(p+maxlen) = '\0';
  112.       *(p+maxlen-1) = 'E';
  113.    }
  114.    strcpy(outst,p);                      // copy to the dest string
  115.    return(outst);
  116. }
  117.