home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 344_01 / fbyte.c < prev    next >
Text File  |  1990-02-21  |  1KB  |  55 lines

  1. /*
  2. HEADER:        ;
  3. TITLE:        Get free diskspace;
  4. VERSION:    1.0;
  5.  
  6. DESCRIPTION:    Calculates the amount of free space on disk.  The drive
  7.         number is entered on the command line  as in the following
  8.         example: fbyte c:.  If no drive number is entered then the
  9.         current drive is assumed.;
  10.  
  11. KEYWORDS:    Dos utilities;
  12. SYSTEM:        MSDOS;
  13. FILENAME:    FBYTE;
  14. WARNINGS:    None;
  15.  
  16. AUTHORS:    Dr. Ronald J. Terry;
  17. COMPILERS:    Turbo C;
  18. */
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. void main(int argc, char *argv[]) /* get command line arguments */
  23. {
  24.     struct dfree space;
  25.     unsigned long freespace;
  26.     unsigned long c,bps,spc;
  27.     unsigned char drive[3],drvno,curdrv;
  28.     argc = argc + 0;
  29.     curdrv = 'A' + getdisk();
  30.     strncpy(drive,argv[1],2);
  31.     drive[3] = NULL;
  32.     drive[0] = toupper(drive[0]);
  33.     if(drive[0])
  34.     {
  35.     drvno = drive[0] - 'A'+ 1;  /* determine drive number */
  36.     }
  37.     else
  38.     {
  39.     drvno = 0;
  40.     drive[0] = curdrv;
  41.     }
  42.     getdfree(drvno,&space);        /* get disk free space */
  43.     c = (unsigned long) space.df_avail;
  44.     bps =(unsigned long) space.df_bsec;
  45.     spc = (unsigned long) space.df_sclus;
  46.     if(space.df_sclus==0xffff)
  47.     printf("Can't determine available space");
  48.     else
  49.     {
  50.     freespace = c*bps*spc;    /* calculate space in bytes */
  51.     printf("Space available on drive %c: = %lu\n",drive[0],freespace);
  52.     }
  53. }
  54.  
  55.