home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / filspace.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  96 lines

  1. /*
  2.  * File......: FILSPACE.PRG
  3.  * Author....: Dave Pearson
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Dave Pearson
  7.  * Date......: $Date$
  8.  * Revision..: $Revision$
  9.  * Log file..: $Logfile$
  10.  *
  11.  * This is an original work by Dave Pearson and is placed in the public
  12.  * domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * $Log$
  18.  *
  19.  */
  20.  
  21. #include "gt_lib.ch"
  22.  
  23. /*  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_FILESPACE()
  26.  *  $CATEGORY$
  27.  *      Disk Drive
  28.  *  $ONELINER$
  29.  *      Calculate the ``real'' size of a file.
  30.  *  $SYNTAX$
  31.  *      GT_FileSpace([<cFileName>],[<ncDrive>]) --> nFileSpace
  32.  *  $ARGUMENTS$
  33.  *      <cFileName> is an optional parameter that is the name of the file
  34.  *      to be checked. This paramater may be a single filename or can be
  35.  *      a wildcard. If not supplied the default is "*.*".
  36.  *
  37.  *      <ncDrive> is an optional parameter that is the id of the drive
  38.  *      for which the calculation is to be done. This paramater can be
  39.  *      either a character value who's first character is taken as the
  40.  *      drive letter or a numeric value where 0 = Default, 1 = A:,
  41.  *      2 = B:, etc... If no parameter is passed the default drive is used.
  42.  *  $RETURNS$
  43.  *      The ``real'' size of the file(s).
  44.  *  $DESCRIPTION$
  45.  *      GT_FileSpace() can be used to calculate the ``real'' size of a
  46.  *      single file or a set of files.
  47.  *
  48.  *      This can be of use if you wish to check that a set of files will
  49.  *      fit into the available space on a drive. As you probably know
  50.  *      a file that is just 1 byte in size will use up one cluster of
  51.  *      disk space, so, for example, if the cluster size of a drive is
  52.  *      2048 bytes a 1 byte file will use up 2048 bytes of storage.
  53.  *  $EXAMPLES$
  54.  *      // Display the ``real'' size of all files in the current directory.
  55.  *
  56.  *      ? GT_FileSpace()
  57.  *
  58.  *      // Display the ``real'' size of the same files if they were
  59.  *      // copied to a network drive called F:.
  60.  *
  61.  *      ? GT_FileSpace(,"F:")
  62.  *
  63.  *      // Now check just the DBF files.
  64.  *
  65.  *      ? GT_FileSpace("*.Dbf","F:")
  66.  *  $END$
  67.  */
  68.  
  69. function GT_FileSpace(cFileName,ncDrive)
  70. local aFiles    := {},;
  71.       nFileSize := -1
  72. default cFileName to "*.*"
  73. aFiles := directory(cFileName)
  74. if !empty(aFiles) .and. GT_SectSize(ncDrive) != -1
  75.    nFileSize := 0
  76.    aeval(aFiles,{|aFile| nFileSize += RealSize(aFile,ncDrive) })
  77. endif
  78. return(nFileSize)
  79.  
  80. /*****************************************************************************
  81. * Function: RealSize()                                                       *
  82. * Syntax..: RealSize(<aFile>,[<ncDrive>]) --> nRealSize                      *
  83. * Usage...: Internal function to do the calculation.                         *
  84. * By......: David A Pearson                                                  *
  85. *****************************************************************************/
  86.  
  87. static function RealSize(aFile,ncDrive)
  88. local nRealSize := 0,;
  89.       nCluster  := GT_SectSize(ncDrive)*GT_SecPClus(ncDrive)
  90. nRealSize := aFile[F_SIZE]/nCluster
  91. if nRealSize != int(nRealSize)
  92.    nRealSize := int(nRealSize)+1
  93. endif
  94. nRealSize *= nCluster
  95. return(nRealSize)
  96.