Binding to a Specific Disk Drive

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

If you know in advance which drive you want to bind to (for example, drive C, or the shared folder \\accounting\receivables), you can use the GetDrive method to bind directly to the drive. This allows you to retrieve information for a specific drive, without having to return and iterate through an entire collection.

The GetDrive method requires a single parameter: the driver letter of the drive or the UNC path to the shared folder. To specify a drive letter, you can use any of the following formats:

  • C
  • C:
  • C:\

The script shown in Listing 4.2 creates an instance of the FileSystemObject, uses the GetDrive method to bind directly to drive C, and then echoes the amount of available space on the drive.

Listing 4.2   Binding to a Single Drive

1 2 3 
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objDrive = objFSO.GetDrive("C:") Wscript.Echo "Available space: " & objDrive.AvailableSpace

Notice that no For Each loop is required to retrieve the drive properties. This is because the script returns an individual drive object rather than a collection of drive objects. Therefore, there is no collection to iterate through.


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