Returning a Collection of Disk Drives

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Before you can manage disk drives on a computer, you need to know which disk drives are actually available on that computer. The FileSystemObject allows you to return a collection of all the drives installed on a computer, including removable drives and mapped network drives (in other words, any drive with a drive letter).

To return this collection, create an instance of the FileSystemObject, and then create a reference to the Drives property. After the collection has been returned, you can use a For Each loop to iterate through the collection.

For example, the script in Listing 4.1 returns a collection of all the drives installed on a computer and then echoes the drive letter for each drive in the collection.

Listing 4.1   Enumerating All the Drives on a Computer

1 2 3 4 5 
Set objFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = objFSO.Drives For Each objDrive in colDrives     Wscript.Echo "Drive letter: " & objDrive.DriveLetter Next

For a complete list of drive properties available using the FileSystemObject, see Table 4.2 later in this chapter.


send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net