Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.filesystem 
StorageVolume 
Packageflash.filesystem
Classpublic class StorageVolume
InheritanceStorageVolume Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

A StorageVolume object includes properties defining a mass storage volume. This class is used in two ways:
  • The storageVolume property of a StorageVolumeChangeEvent object is a StorageVolume object. This object represents the storage volume that has been mounted or unmounted.
  • The StorageVolumeInfo.storageVolumeInfo.getStorageVolumes() method returns a vector of StorageVolume objects. Each of these StorageVolume objects represents a mounted storage volume.

View the examples

See also



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  AIR-only drive : String
[read-only] The volume drive letter on Windows.
StorageVolume
  AIR-only fileSystemType : String
[read-only] The type of file system on the storage volume (such as "FAT", "NTFS", "HFS", or "UFS").
StorageVolume
  AIR-only isRemovable : Boolean
[read-only] Whether the operating system considers the storage volume to be removable (true) or not (false).
StorageVolume
  AIR-only isWritable : Boolean
[read-only] Whether a volume is writable (true) or not (false).
StorageVolume
  AIR-only name : String
[read-only] The name of the volume.
StorageVolume
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  AIR-only rootDirectory : File
[read-only] A File object corresponding to the root directory of the volume.
StorageVolume
Public Methods
 MethodDefined By
  
AIR-only StorageVolume(rootDirPath:File, name:String, writable:Boolean, removable:Boolean, fileSysType:String, drive:String)
The constructor function.
StorageVolume
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail
AIR-only 

drive

property
drive:String  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

The volume drive letter on Windows. On other platforms, this property is set to null.



Implementation
    public function get drive():String
AIR-only 

fileSystemType

property 
fileSystemType:String  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

The type of file system on the storage volume (such as "FAT", "NTFS", "HFS", or "UFS").



Implementation
    public function get fileSystemType():String

Example  ( How to use this example )
The following code lists the native path for the root directory and the file system type of each mounted storage volume:
var volumes:Vector.<StorageVolume> = new Vector.<StorageVolume>;
volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
for (var i:int = 0; i < volumes.length; i++)
{
    trace(volumes[i].rootDirectory.nativePath, "(" + volumes[i].fileSystemType + ")");
}
AIR-only 

isRemovable

property 
isRemovable:Boolean  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

Whether the operating system considers the storage volume to be removable (true) or not (false).

The following table lists the values StorageVolume.isRemovable property for various types of devices:

Type of deviceMac OSWindowsLinux
CD/DVD (fixed)truetruetrue
USB flash drivetruetruetrue
USB hard srivefalsefalsetrue
FireWire hard drivefalsefalsetrue
Shared volumetruefalse- 1
Network drivefalsefalsefalse
Storage card reader (empty)- 2false- 2
Storage card reader (with SD/CF card)truetruetrue

1 Linux does not have a concept of a shared volume.

2 On Windows, an empty card reader is listed as a non-removable device. On Mac OS and Linux, empty car readers are not listed as storage volumes.



Implementation
    public function get isRemovable():Boolean

Example  ( How to use this example )
The following code outputs a list of non-removable storage volumes, followed by a list of removable storage volumes:
var volumes:Vector.<StorageVolume> = new Vector.<StorageVolume>;
volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();

trace("Non-removeable volumes:");
for (var i:int = 0; i < volumes.length; i++)
{
    if (!volumes[i].isRemovable)
    {
        trace(volumes[i].rootDirectory.nativePath);
    }
}

trace("\nRemoveable volumes:");
for (i = 0; i < volumes.length; i++)
{
    if (volumes[i].isRemovable)
    {
        trace(volumes[i].rootDirectory.nativePath);
    }
}
AIR-only 

isWritable

property 
isWritable:Boolean  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

Whether a volume is writable (true) or not (false).

Note: You can determine the amount of space available on a volume by calling the rootDirectory.spaceAvailble property of the StorageVolume object.



Implementation
    public function get isWritable():Boolean

See also

flash.fileSystem.File.spaceAvailable

Example  ( How to use this example )
The following code outputs a list of writable storage volumes and the space available on each:
var volumes:Vector.<StorageVolume> = new Vector.<StorageVolume>;
volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();

for (var i:int = 0; i < volumes.length; i++)
{
    if(volumes[i].isWritable)
    {         
        trace(volumes[i].rootDirectory.nativePath, volumes[i].rootDirectory.spaceAvailable);
    }
}
AIR-only 

name

property 
name:String  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

The name of the volume. If there is no name, this property is set to null.



Implementation
    public function get name():String

Example  ( How to use this example )
The following code lists the native path for the root directory and the file system name (if there is one) of each mounted storage volume:
var volumes:Vector.<StorageVolume> = new Vector.<StorageVolume>;
volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
for (var i:int = 0; i < volumes.length; i++)
{
    var name:String = new String();
    if (volumes[i].name)
    {
        name = "(" + volumes[i].name + ")";
    }
    trace(volumes[i].rootDirectory.nativePath, name);
}
AIR-only 

rootDirectory

property 
rootDirectory:File  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

A File object corresponding to the root directory of the volume.



Implementation
    public function get rootDirectory():File

Example  ( How to use this example )
The following code lists the native path for the root directory of each mounted storage volume:
var volumes:Vector.<StorageVolume> = new Vector.<StorageVolume>;
volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
for (var i:int = 0; i < volumes.length; i++)
{
    trace(volumes[i].rootDirectory.nativePath);
}
Constructor Detail
AIR-only 

StorageVolume

()Constructor
public function StorageVolume(rootDirPath:File, name:String, writable:Boolean, removable:Boolean, fileSysType:String, drive:String)

Language Version: ActionScript 3.0
Runtime Versions: AIR 2

The constructor function. Generally, you do not call this constructor function directly (to create new StorageVolume objects). Rather, you reference StorageVolume objects by accessing the storageVolume property of a StorageVolumeChangeEvent object or by calling StorageVolumeInfo.storageVolumeInfo.getStorageVolumes().

Parameters
rootDirPath:File
 
name:String
 
writable:Boolean
 
removable:Boolean
 
fileSysType:String
 
drive:String
StorageVolumeExample.as

The following code lists the properties of each mounted storage volume:
package
{
    import flash.display.Sprite;
    import flash.filesystem.StorageVolume;
    import flash.filesystem.StorageVolumeInfo;

    public class StorageVolumeExample extends Sprite
    {
        public function StorageVolumeExample()
        {
            var volumes:Vector.<StorageVolume> = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
            for (var i:int = 0; i < volumes.length; i++)
            {
                var volume:StorageVolume = volumes[i];
                trace("nativePath:", volume.rootDirectory.nativePath);
                trace("fileSystemType:", volume.fileSystemType);
                trace("isRemovable:", volume.isRemovable);
                trace("isWritable:", volume.isWritable);
                trace("drive:", volume.drive);
                trace("name:", volume.name);
                trace("________________________________________________________");
            }
        }
    }
}
StorageVolumeChangeEventExample.as

The following code lists the properties of each storage volume that becomes mounted or unmounted. Note that the storageVolume property of the StorageVolumeChangeEvent is only set for the storageVolumeMount event; it is null for the storageVolumeUnmount event:
package
{
    import flash.display.Sprite;
    import flash.events.StorageVolumeChangeEvent;
    import flash.filesystem.StorageVolume;
    import flash.filesystem.StorageVolumeInfo;

    public class StorageVolumeChangeEventExample extends Sprite
    {
        public function StorageVolumeChangeEventExample()
        {
            StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, mountEventHandler);
            StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, unmountEventHandler);
        }
        public function mountEventHandler(event:StorageVolumeChangeEvent):void
        {            
            var volume:StorageVolume = event.storageVolume;
            trace("VOLUME MOUNTED:");
            trace("nativePath:", event.rootDirectory.nativePath);
            trace("fileSystemType:", volume.fileSystemType);
            trace("isRemovable:", volume.isRemovable);
            trace("isWritable:", volume.isWritable);
            trace("drive:", volume.drive);
            trace("name:", volume.name);
            trace();
        }
        public function unmountEventHandler(event:StorageVolumeChangeEvent):void
        {            
            trace("VOLUME UNMOUNTED:");
            trace("nativePath:", event.rootDirectory.nativePath);
            trace();
        }        
    }
}