4D v16.3

VOLUME ATTRIBUTES

Home

 
4D v16.3
VOLUME ATTRIBUTES

VOLUME ATTRIBUTES 


 

VOLUME ATTRIBUTES ( volume ; size ; used ; free ) 
Parameter Type   Description
volume  String in Volume name
size  Real in Volume size expressed in bytes
used  Real in Used space expressed in bytes
free  Real in Free space expressed in bytes

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.

Note: 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
 
 C_STRING(31;$0)
 C_STRING(255;$vsDocName)
 C_LONGINT($vlNbVolumes;$vlVolume)
 C_REAL($1;$vlSize;$vlUsed;$vlFree)
 C_TIME($vhDocRef)
 
  ` Initialize function result
 $0:=""
  ` 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>=($1+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
                $0:=$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 

Product: 4D
Theme: System Documents
Number: 472

The OK variable is changed by the commandThis command modifies the Error system variableThis command can be run in preemptive processes

 
HISTORY 

Created: 4D v6

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)