Enumerator Object (Windows Scripting - JScript)

 

Enables enumeration of items in a collection.

Syntax

enumObj = new Enumerator([collection]) 

Arguments

  • enumObj
    Required. The variable name to which the Enumerator object is assigned.

  • collection
    Optional. Any Collection object.

Remarks

Collections differ from arrays in that the members of a collection are not directly accessible. Instead of using indexes, as you would with arrays, you can only move the current item pointer to the first or next element of a collection.

The Enumerator object provides a way to access any member of a collection and behaves similarly to the For...Each statement in VBScript.

The following code shows the usage of the Enumerator object:

function ShowDrives()
{
    var s = "";
    var bytesPerGB = 1024 * 1024 * 1024;

    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var e = new Enumerator(fso.Drives);

    e.moveFirst();
    while (e.atEnd() == false)
    {
        var drv = e.item();

        s += drv.Path + " - ";

        if (drv.IsReady)
        {
            var freeGB = drv.FreeSpace / bytesPerGB;
            var totalGB = drv.TotalSize / bytesPerGB;

            s += freeGB.toFixed(3) + " GB free of ";
            s += totalGB.toFixed(3) + " GB";
        }
        else
        {
            s += "Not Ready";
        }

        s += "<br />";

        e.moveNext();
    }
    return(s);
}

Properties

The Enumerator object has no properties.

Methods

atEnd Method | item Method | moveFirst Method | moveNext Method

Requirements

Version 3

Change History

Date

History

Reason

January 2010

Modified code example.

Information enhancement.

March 2009

Modified code example.

Information enhancement.

See Also

Boolean Object (Windows Scripting - JScript)