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

  1. #define INC_SUB
  2. #define DIRECTORY 0x10
  3. #define ALL_FILES 0x27
  4.  
  5. #include <os2.h>
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <string.h>
  9.  
  10. long main(int argc, char* *argv);
  11. long td(char *directory);
  12.  
  13. int clstr_sz;
  14.  
  15. long main(argc, argv)
  16. int argc;
  17. char **argv;
  18. {
  19.     USHORT usDisk, usDrive;
  20.     ULONG usLogicalDriveMap;
  21.     FSALLOCATE FSInfoBuf;
  22.     char drive[3];
  23.  
  24.     if (argc > 1)
  25.         usDisk = toupper(argv[1][0]) - '@';
  26.  
  27.     if (argc == 1 || usDisk < 1 || usDisk > 26)
  28.        DosQCurDisk(&usDisk, &usLogicalDriveMap);
  29.     else
  30.        DosQCurDisk(&usDrive, &usLogicalDriveMap);
  31.  
  32.     if (!(usLogicalDriveMap & (1 << (usDisk-1))))
  33.     {
  34.     printf("Invalid Drive %c: specified", usDisk + '@');
  35.     return 0;
  36.     }
  37.  
  38.     if (DosQFSInfo(usDisk, 1, (PBYTE) &FSInfoBuf, sizeof(FSInfoBuf))) {
  39.        printf(" %c:", usDisk + '@');
  40.        puts("    ....Bad Drive Specifier....");
  41.        return 0;
  42.     }
  43.  
  44.     clstr_sz = (int) (FSInfoBuf.cSectorUnit*FSInfoBuf.cbSector);
  45.  
  46.     sprintf(drive, "%c:", usDisk+'@');
  47.  
  48.     return td(drive);
  49. }
  50.  
  51.  
  52. long td(directory)
  53. char *directory;
  54. {
  55.     HDIR hdir            = 0xFFFF;
  56.     USHORT usSearchCount = 1;
  57.     FILEFINDBUF findbuf;
  58.     char flname[80], sdir[64], *dir;
  59.     unsigned long bytes = 0l;
  60.  
  61.     sprintf(flname, "%s\\*.*", directory);
  62.  
  63.     if (!DosFindFirst(flname, &hdir, DIRECTORY, &findbuf,
  64.         sizeof(findbuf), &usSearchCount, 0L))
  65.         do {
  66.  
  67.         if (strcmp(findbuf.achName, ".") && strcmp(findbuf.achName, "..") &&
  68.         findbuf.attrFile == DIRECTORY)
  69.         {
  70.         sprintf(sdir, "%s\\%s", directory, findbuf.achName);
  71.         bytes += td(sdir);
  72.         }
  73.  
  74.         } while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
  75.  
  76.  
  77.     hdir        = 0xFFFF;
  78.     usSearchCount   = 1;
  79.  
  80.     if (!DosFindFirst(flname, &hdir, ALL_FILES, &findbuf,
  81.         sizeof(findbuf), &usSearchCount, 0L))
  82.         do {
  83.            bytes  += findbuf.cbFileAlloc;
  84.     } while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
  85.  
  86.     bytes += clstr_sz;
  87.     dir = strchr(directory, '\\');
  88.     printf("%s\\ %lu K\n", (dir) ? dir : directory, bytes/1024);
  89.  
  90.     return bytes;
  91.  
  92. }
  93. 
  94.