Folder object returned by the GetFolder method of the Javascript FileSystemObject (FSO) provides the access to the SubFolders collection property that returns a collection of items which can be read using javascript Enumerator collection type object. You can pass the SubFolders collection property of 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 SubFolders collection of client’s PC using the folder object returned by the GetFolder method. 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.

Syntax for FSO GetFolder SubFolders Collection

folderObj.SubFolders

Above syntax can be used to retrieve the enumerator type subfolders collection of the specified folder.

Example of Javascript FSO SubFolders Collection

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // object created for folder object returned by GetFolder method
    var folderObj = fso.GetFolder("C:\\Temp");

    // creates the enumerator type collection of sub folders
    var Collection = new Enumerator(folderObj.SubFolders);

    var Obj;

    for (Collection.moveFirst(); !Collection.atEnd(); Collection.moveNext()) {
        Obj = Collection.item();
        document.write(Obj.Name);
        document.write("<br />");
    }

    // Output: 
    // documents_folder 
    // folder2 
    // myFolder
</script>

Also read the tutorial: Javascript FSO Files Collection to learn how to get the collection of files at the specified location.

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.