home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / DIRSIZE.ZIP / DIRSIZE.C next >
C/C++ Source or Header  |  1990-12-27  |  3KB  |  101 lines

  1.  
  2. #define INCL_DOSFILEMGR
  3. #define INCL_DOSPROCESS
  4. #include <os2.h>
  5. #include <stdio.h>
  6.  
  7. /******************************************************************
  8. The FILEFINDBUF structure.
  9. Field             Description
  10. ────────────────────────────────────────────────────────────────────────────
  11. fdateCreation                         Specifies the date the file was created.
  12. ftimeCreation                         Specifies the time the file was created.
  13. fdateLastAccess                      Specifies the date the file was last accessed.
  14. ftimeLastAccess                      Specifies the time the file was last accessed.
  15. fdateLastWrite                         Specifies the date the file was last written to.
  16. ftimeLastWrite                         Specifies the time the file was last written to.
  17. cbFile                                 Specifies the end of file data.
  18. cbFileAlloc                             Specifies the allocated file size.
  19. attrFile                                 Specifies the file attributes.
  20. cchName                                  Specifies the length of the null-terminated filename.
  21. achName[CCHMAXPATHCOMP]         Specifies the null-terminated filename.
  22.  
  23. The FDATE structure is used in various other structures to specify the day,
  24. month, and year.
  25.  
  26. _FDATE {
  27.     unsigned day     : 5;
  28.     unsigned month   : 4;
  29.     unsigned year    : 7;
  30. } FDATE;
  31. Field  Description
  32. ────────────────────────────────────────────────────────────────────────────
  33. day    Specifies the day.
  34. month  Specifies the month.
  35. year   Specifies the year.
  36.  
  37. *****************************************************************************/
  38. void cdecl main ( int argc, char *argv[] )
  39. {
  40.     HDIR    hdir;
  41.     USHORT  usSearch;
  42.     FILEFINDBUF findbuf;
  43.     USHORT Error = 0;
  44.     ULONG allocated_dirsize = 0;
  45.     ULONG actual_dirsize = 0;
  46.     hdir = HDIR_SYSTEM;
  47.     usSearch = 1;
  48.     if (argc < 2 )
  49.             {
  50.             printf("\nUsage: DIRSIZE filename.ext\n");
  51.       printf("wildcard \"*,?\"characters are OK");
  52.             DosExit(0,0);
  53.             }
  54.     Error = DosFindFirst (argv[1],
  55.                                                    &hdir,
  56.                                                    FILE_NORMAL,
  57.                                                    &findbuf,
  58.                                                    sizeof(findbuf),
  59.                                                    &usSearch,
  60.                                                    0L);
  61.     if (Error != 0)
  62.             {
  63.             printf("USAGE: DIRSIZE filespec.ext");
  64.             DosExit(0,0);
  65.             }
  66.     else
  67.             {
  68.       printf("%s           \t%lu\t%lu\t%2d-%2d-%2d\n",
  69.                       findbuf.achName,
  70.               findbuf.cbFileAlloc,
  71.               findbuf.cbFile,
  72.                       findbuf.fdateLastWrite.month,
  73.               findbuf.fdateLastWrite.day,
  74.               findbuf.fdateLastWrite.year+80);
  75.  
  76.             allocated_dirsize += findbuf.cbFileAlloc;
  77.             actual_dirsize += findbuf.cbFile;
  78.             }
  79.     do
  80.         {
  81.                 usSearch = 1;
  82.                 Error = DosFindNext (hdir, &findbuf, sizeof(findbuf), &usSearch);
  83.                 if (Error == 0)
  84.             {   /* _dos_findnext */
  85.       printf("%s          \t%lu\t%lu\t%2d-%2d-%2d\n",
  86.                       findbuf.achName,
  87.               findbuf.cbFileAlloc,
  88.               findbuf.cbFile,
  89.                       findbuf.fdateLastWrite.month,
  90.               findbuf.fdateLastWrite.day,
  91.               findbuf.fdateLastWrite.year+80);
  92.  
  93.  
  94.                         allocated_dirsize += findbuf.cbFileAlloc;
  95.                         actual_dirsize += findbuf.cbFile;
  96.             }
  97.         } while (usSearch != 0);
  98.     printf("\nAllocated Directory Size: %lu bytes - Actual Directory Size: %lu bytes.\n",allocated_dirsize, actual_dirsize);
  99.     DosFindClose (hdir);
  100. }
  101.