"Drive" Objects Representing Disk Drives

This section describes Drive object properties. A tutorial example is provided on how to list all drives and their properties on the local machine.

"Drive": An object representing a drive of the file system. It offers the following methods and properties:

Here is a VBScript example showing you how to use Drive object properties:

<html>
<body>
<!-- drive_test.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<pre>
<script language="vbscript">
   ' Creating a FileSystemObject object
   set fs = CreateObject("Scripting.FileSystemObject")

   ' Display all drives and their properties
   set ds = fs.Drives
   document.writeln("List of drives:")
   for each d in ds
      document.writeln("Drive Letter = " & d.DriveLetter)
      document.writeln("Drive Type = " & d.DriveType)
      document.writeln("Is Ready = " & d.IsReady)
      document.writeln("Path = " & d.Path)
      document.writeln("Share Name = " & d.ShareName)
      if d.IsReady then 
         document.writeln("File System = " & d.FileSystem)
         document.writeln("Serial Number = " & d.SerialNumber)
         document.writeln("Volume Name = " & d.VolumeName)
         document.writeln("Total Size = " & d.TotalSize)
         document.writeln("Free Space = " & d.FreeSpace)
      end if
   next
</script>
</pre>
</body>
</html>

When you load this example into IE, you will get a security warning. You can ignore it and get the output:

List of drives:
Drive Letter = C
Drive Type = 2
Is Ready = True
Path = C:
Share Name = 
File System = NTFS
Serial Number = 1545214583
Volume Name = New Volume
Total Size = 9697603584
Free Space = 4838227968
Drive Letter = D
Drive Type = 4
Is Ready = False
Path = D:
Share Name = 

Note that: Drive "D:" is my CD-ROM, which is not ready, because it is not loaded with any CD.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

scrrun.dll - Scripting Runtime DLL Library

 Scripting Runtime DLL Library Overview

 "Dictionary" Objects to Store Keys and Values

 "FileSystemObject" Objects to Manage File Systems

"Drive" Objects Representing Disk Drives

 "Folder" Objects Representing File Folders

 "File" Objects Representing Files

 "TextStream" Objects Representing File Input and Output

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 PDF Printing Version