BaH.Volumes: Functions Types Modinfo Source  

Volumes

Volumes is a small cross-platform module which provides useful volume/device information support for BlitzMax.

The module is essentially split into two parts, that of volume information, and some functions which give user-specific directory paths.

Volume Information

Enables access to all volumes on the system, as well as drive-details such as free and total space for the volume.

To get a list of volumes on the current system, simply call ListVolumes which returns a list of TVolume objects, from which you have access to the extra information.
You can also retrieve size information directly using GetVolumeSize and GetVolumeFreeSpace.

User Directories

Useful for the application developer is access to user-specific directories, like their home and document directories. The Volumes module provides access to four of these for all supported platforms: GetUserAppDir, GetUserDesktopDir, GetUserDocumentsDir, and GetUserHomeDir.

Functions Summary

GetCustomDir Returns the custom directory path.
GetUserAppDir Returns the user directory for application data.
GetUserDesktopDir Returns the user Desktop directory.
GetUserDocumentsDir Returns the user Documents directory.
GetUserHomeDir Returns the user home directory.
GetVolumeFreeSpace Returns the amount of free space (in bytes) on the given volume.
GetVolumeInfo Populates and returns a TVolume object.
GetVolumeSize Returns the size (in bytes) of the given volume.
ListVolumes Returns a list of volumes on the system.

Types Summary

TVolume A system Volume.

Functions

Function GetCustomDir:String(dirType:Int)
DescriptionReturns the custom directory path.
InformationThe following table lists valid dirType -
PlatformdirTypeDescription
MacDT_SHAREDUSERDATAThe Shared documents folder.

Returns Null if dirType is not valid for the platform.


Function GetUserAppDir:String()
DescriptionReturns the user directory for application data.
InformationThe table lists examples for the various platforms -
PlatformExampleEquivalent
Linux/home/username~
Mac OS/Users/username/Library/Application Support~/Library/Application Support
Win32C:\Documents and Settings\username\Application Data 
Example
SuperStrict

Framework BaH.Volumes
Import BRL.Standardio

Print GetUserAppDir()

Function GetUserDesktopDir:String()
DescriptionReturns the user Desktop directory.
InformationThe table lists examples for the various platforms -
PlatformExampleEquivalent
Linux/home/username/Desktop~/Desktop
Mac OS/Users/username/Desktop~/Desktop
Win32C:\Documents and Settings\username\Desktop 
Example
SuperStrict

Framework BaH.Volumes
Import BRL.Standardio

Print GetUserDesktopDir()

Function GetUserDocumentsDir:String()
DescriptionReturns the user Documents directory.
InformationThe table lists examples for the various platforms -
PlatformExampleEquivalent
Linux/home/username/Documents~/Documents
Mac OS/Users/username/Documents~/Documents
Win32C:\Documents and Settings\username\My Documents 
Example
SuperStrict

Framework BaH.Volumes
Import BRL.Standardio

Print GetUserDocumentsDir()

Function GetUserHomeDir:String()
DescriptionReturns the user home directory.
InformationThe table lists examples for the various platforms -
PlatformExampleEquivalent
Linux/home/username~
Mac OS/Users/username~
Win32C:\Documents and Settings\username 
Example
SuperStrict

Framework BaH.Volumes
Import BRL.Standardio

Print GetUserHomeDir()

Function GetVolumeFreeSpace:Long(vol:String)
DescriptionReturns the amount of free space (in bytes) on the given volume.
InformationParameters:
  • vol : the name of the volume
Example
SuperStrict

Framework bah.volumes
Import brl.standardio

Local vol:String

?win32
vol = "C:\"
?linux
vol = "/"
?macos
vol = "/"
?

Print "Freespace :"
Print vol + " = " + (GetVolumeFreeSpace(vol) / 1024) + " kb"

Function GetVolumeInfo:TVolume(vol:String)
DescriptionPopulates and returns a TVolume object.
InformationParameters:
  • vol : the name of the volume

Function GetVolumeSize:Long(vol:String)
DescriptionReturns the size (in bytes) of the given volume.
InformationParameters:
  • vol : the name of the volume
Example
SuperStrict

Framework bah.volumes
Import brl.standardio

Local vol:String

?win32
vol = "C:\"
?linux
vol = "/"
?macos
vol = "/"
?

Print "Total space :"
Print vol + " = " + (GetVolumeSize(vol) / 1024) + " kb"

Function ListVolumes:TList()
DescriptionReturns a list of volumes on the system.
Example
SuperStrict

Framework bah.volumes
Import brl.standardio

Local list:TList = ListVolumes()

If list Then
	Print "Volumes :"

	For Local v:TVolume = EachIn list
	
		'If v.available Then
			Print "~t" + v.volumeName + "  -  " + v.volumeDevice + " (" +  v.volumeType +  ") -  " + ((v.volumeFree / 1024) / 1024) + "mb"
		'End If
	
	Next
End If

Types

Type TVolume
DescriptionA system Volume.
Fields Summary
available , volumeDevice , volumeFree , volumeName , volumeSize , volumeType
Methods Summary
Refresh Refreshes size/free info for the volume.
Field available:Int
DescriptionTrue if available, false if not.
Field volumeDevice:String
DescriptionThe device name.
Field volumeFree:Long
DescriptionCached free space (in bytes)
InformationFor the current free space, Refresh first.
Field volumeName:String
DescriptionThe volume name.
Field volumeSize:Long
DescriptionCached volume size (in bytes)
InformationFor the current size, Refresh first.
Field volumeType:String
DescriptionThe system type.
Method Refresh() Abstract
DescriptionRefreshes size/free info for the volume.

Module Information

Version1.05
LicenseFree for commercial and personal use
AuthorBruce A Henderson
Copyright(c) 2006, 2007 Bruce A Henderson
ModserverBRL
History1.05
HistoryAdded GetCustomDir function.
History1.04
HistoryUpdated Win32 to use SHGetFolderPathW instead of SHGetFolderPathA
History1.03
HistoryAdded new functions : GetUserHomeDir, GetUserDesktopDir, GetUserAppDir, GetUserDocumentsDir.
History1.02
HistoryAdded Mac support.
History1.01
HistoryFixed win32 type returning the wrong string.
History1.00 Initial Release