Skip to main content
Version: 21 R3

VOLUME ATTRIBUTES

VOLUME ATTRIBUTES ( volume : Text ; size : Real ; used : Real ; free : Real )

ParameterTypeDescription
volumeText→Volume name
sizeReal←Volume size expressed in bytes
usedReal←Used space expressed in bytes
freeReal←Free space expressed in bytes
History
ReleaseChanges
6Created

Description​

The VOLUME ATTRIBUTES command returns, expressed in bytes, the size, the used space and the free space for the volume whose name you pass in volume.If volume indicates a non-mounted remote volume, the OK variable is set to 0 and the three parameters return -1.

Example​

Your application includes some batch operations running the night or the week-end that store huge temporary files on disk. To make this process as automatic and flexible as possible, you write a routine that will automatically find the first volume whose free space is sufficient for your temporary files. You might write the following project method:

  // Find volume for space Project Method
  // Find volume for space ( Real ) -> String
  // Find volume for space ( Space needed in bytes ) -> Volume name or Empty string
 
 #DECLARE($space : Real) -> $result : Text
 var $vsDocName : Text
 var $vlNbVolumes;$vlVolume : Integer
 var $vlSize;$vlUsed;$vlFree : Real
 var $vhDocRef : Time
 
  // Initialize function result
 $result:=""
  // Protect all I/O operations with an error interruption method
 ON ERR CALL("ERROR METHOD")
  // Get the list of the volumes
 ARRAY STRING(31;$asVolumes;0)
 gError:=0
 VOLUME LIST($asVolumes)
 If(gError=0)
  // If running on windows, skip the (usual) two floppy drives
    If(On Windows)
       $vlVolume:=Find in array($asVolumes;"A:\\")
       If($vlVolume>0)
          DELETE FROM ARRAY($asVolumes;$vlVolume)
       End if
       $vlVolume:=Find in array($asVolumes;"B:\\")
       If($vlVolume>0)
          DELETE FROM ARRAY($asVolumes;$vlVolume)
       End if
    End if
    $vlNbVolumes:=Size of array($asVolumes)
  // For each volume
    For($vlVolume;1;$vlNbVolumes)
  // Get the size, used space and free space
       gError:=0
       VOLUME ATTRIBUTES($asVolumes{$vlVolume};$vlSize;$vlUsed;$vlFree)
       If(gError=0)
  // Is the free space large enough (plus an extra 32K) ?
          If($vlFree>=($space+32768))
  // If so, check if the volume is unlocked...
             $vsDocName:=$asVolumes{$vlVolume}+Char(Directory symbol)+"XYZ"+String(Random)+".TXT"
             $vhDocRef:=Create document($vsDocName)
             If(OK=1)
                CLOSE DOCUMENT($vhDocRef)
                DELETE DOCUMENT($vsDocName)
  // If everything's fine, return the name of the volume
                $result:=$asVolumes{$vlVolume}
                $vlVolume:=$vlNbVolumes+1
             End if
          End if
       End if
    End for
 End if
 ON ERR CALL("")

Once this project method is added to your application, you can for instance write:

 $vsVolume:=Find volume for space(100*1024*1024)
 If($vsVolume#"")
  // Continue
 Else
    ALERT("A volume with at least 100 MB of free space is required!")
 End if

See also​

VOLUME LIST

Properties​

Command number472
Thread safeyes
Modifies variablesOK, error