Javascript FileSystemObject Drives property returns a collection of items that can be read using javascript Enumerator collection type object. You can pass the Drives collection property of Scripting FileSystemObject to the Enumerator constructor as a parameter that makes it possible to access the items in sequential order using javascript for loop. In the tutorial about Javascript Enumerator object we discussed about the four methods supported by enumerator that enable you to read the items of the associated collection passed to its class constructor. Here we will learn how to create the FileSystemObject and access the Drives of client’s PC using its Drives collection property. Javascript Enumerator collection type object does not allow accessing the items directly by passing their index position. It works on pointer mechanism that returns the item at the current pointer position.

Javascript Code for FileSystemObject Drives Property

<script type="text/javascript">

    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // create Enumerator type collection of Drives retrieved from the client's PC.
    var Enum = new Enumerator(fso.Drives);

    var driveInfo;

    // for loop over the items of Enumerator created above.
    for (Enum.moveFirst(); !Enum.atEnd(); Enum.moveNext()) {
        // read item at current pointer position and assign that value to the driveInfo variable.
        driveInfo = Enum.item();

        // print the value on page.
        document.write(driveInfo + "<br />");
    }

</script> 

Above javascript code executes automatically at page load and returns the collection of Drives and their related information retrieved from the client’s system.

Note: this function works only if the client’s web browser security allows creating the FileSystemObject through its automation server that enables you to access the client side properties.

Continue to next tutorial: Javascript FileSystemObject BuildPath Method to learn how to build a path by concatenating parameters.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.