Export (0) Print
Expand All

moveFirst Method

Resets the current item in an Enumerator object to the first item.

function moveFirst()

Remarks

If there are no items in the collection, the current item is set to undefined.

Example

In following example, the moveFirst method is used to evaluate members of the Drives collection from the beginning of the list:

function ShowFirstAvailableDrive(){
   var fso, s, e, x;                //Declare variables.
   fso = new ActiveXObject("Scripting.FileSystemObject");
   e = new Enumerator(fso.Drives);  //Create Enumerator object.
   e.moveFirst();                   //Move to first drive.
   s = "";                          //Initialize s.
   do 
   {
      x = e.item();                 //Test for existence of drive.
      if (x.IsReady)                //See if it's ready.
      {
         s = x.DriveLetter + ":";   //Assign 1st drive letter to s.
         break;
      }
      else
         if (e.atEnd())             //See if at the end of the collection.
         {
            s = "No drives are available";
            break;
         }
      e.moveNext();                 //Move to the next drive.
   }
   while (!e.atEnd());              //Do while not at collection end.
   return(s);                       //Return list of available drives.
}

Requirements

Version 3

See Also

atEnd Method | item Method | moveNext Method

Applies To: Enumerator Object

Show:
© 2014 Microsoft