home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2UTIL.ZIP / SIZE.C < prev    next >
Text File  |  1990-05-21  |  2KB  |  60 lines

  1. #define INCL_SUB 1
  2. #include "os2.h"
  3. #include "stdio.h"
  4. #include "math.h"
  5. #include "ctype.h"
  6. #include "string.h"
  7. #include "stdlib.h"
  8.  
  9. #define HALF    171
  10. #define QUARTER 172
  11.  
  12. int main(int argc, char* *argv);
  13. main(argc, argv)
  14. int argc;
  15. char *argv[];
  16. {
  17.     int flcnt = 0;
  18.     unsigned long filetot = 0L, diskftot = 0L, diskmtot = 0L, hardtot = 0L;
  19.     HDIR hdir          = 0xFFFF;
  20.     USHORT usSearchCount  = 1;
  21.     FILEFINDBUF findbuf;
  22.     char mask[80];
  23.  
  24.     puts("SIZE Vers. 1.0 - Jan. 1990 - OS/2 Version\n");
  25.     if (argc > 2) {
  26.        puts("Invalid parameter(s)");
  27.        puts("or file(s) not found");
  28.        exit(1);
  29.     }
  30.     if (argc == 1)
  31.        strcpy(mask, "*.*");
  32.     else {
  33.        strcpy(mask, argv[1]);
  34.        if ('A'<=toupper(argv[1][0]) && toupper(argv[1][0])<='Z' && argv[1][1] == ':' &&
  35.            (strlen(argv[1]) == 2 || (strlen(argv[1]) == 3 && argv[1][2] == '\\')) )
  36.           strcat(mask, "*.*");
  37.     }
  38.  
  39.     if (!DosFindFirst(mask, &hdir, 0x00, &findbuf,
  40.         sizeof(findbuf), &usSearchCount, 0L))
  41.         do {
  42.                ++flcnt;
  43.            filetot    += findbuf.cbFile;
  44.            diskmtot += 512L*(long)ceil((double)findbuf.cbFile/512.0);
  45.            diskftot += 1024L*(long)ceil((double)findbuf.cbFile/1024.0);
  46.            hardtot    += 2048L*(long)ceil((double)findbuf.cbFile/2048.0);
  47.         }
  48.         while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
  49.     else {
  50.                puts("Invalid parameter(s)");
  51.                puts("or file(s) not found");
  52.                exit(1);
  53.        }
  54.     printf("%8lu bytes in %4d file%c\n", filetot, flcnt, (flcnt == 1) ? ' ' : 's');
  55.     printf("%8lu bytes required on 3%c\" diskette(s)\n", diskmtot, HALF);
  56.     printf("%8lu bytes required on 5%c\" diskette(s)\n", diskftot, QUARTER);
  57.     printf("%8lu bytes required on fixed disk\n", hardtot);
  58.     return(0);
  59. }
  60.