samedi 19 novembre 2016

Determining valid drives on Windows?

I want to present the user with a list of the writable, valid drives on their machine. Using StorageVolumeInfo on OSX there are several drives reported which are not valid for writing user data to ("net", "home", "mobilebackup"). The code below filters those out.

I am not that experienced with how Windows reports drives (user created virtual drives, etc).
Can anyone share their experience and/or tips with filtering out non-valid drives on a PC?

for (var i:int = 0; i < volumes.length; i++) {      
    var rootTest:File = new File(volumes[i].rootDirectory.url);
    trace(volumes[i].name, "spaceAvailable:",rootTest.spaceAvailable);
}

Storage spaceAvailable: 62930288640
net spaceAvailable: 0
home spaceAvailable: 0
MobileBackups spaceAvailable: 0
Dazzle spaceAvailable: 41423425536


<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ift.tt/rYUnH9" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       applicationComplete="onApplicationCompleteHandler(event)" >

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function onApplicationCompleteHandler(event:FlexEvent):void
            {
                var volumes:Vector.<StorageVolume> = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();

                for (var i:int = 0; i < volumes.length; i++) {

                    var rootTest:File = new File(volumes[i].rootDirectory.url);
                    var listing:Array = rootTest.getDirectoryListing();

                    if (volumes[i].isWritable && listing.length > 0){

                        trace("Drive Name:", volumes[i].name);
                        trace("fileSystemType:", volumes[i].fileSystemType);
                        trace("rootDirectory:", volumes[i].rootDirectory.url);
                        trace("removable:", volumes[i].isRemovable);
                        trace(" ");
                    }
                }
            }

        ]]>
    </fx:Script>

</s:WindowedApplication>

Aucun commentaire:

Enregistrer un commentaire