vendredi 18 novembre 2016

Determining valid drives on both OSX and Windows

(I posted an earlier question on this (Accessing attached drives to display in FileSystemTree?) but it didn't get any love. Perhaps it was too dense?)

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 don't have access to a PC right now – and I need to know if this code works on Windows as well: only listing drives which the user has write access to. If one of the brave, few people who still use Flex and are on a PC could run this code and report back, I'd appreciate it.

<?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