YouTip LogoYouTip

Prop Drives

## ASP FileSystemObject: Drives Property The **Drives** property of the `FileSystemObject` (FSO) returns a read-only collection of all available `Drive` objects on the local computer or network share. This collection includes all drives, regardless of their type (removable, fixed, network, CD-ROM, or RAM disk). --- ### Syntax ```vbscript Set drivecoll = FileSystemObject.Drives ``` #### Return Value * Returns a **Drives Collection** containing a `Drive` object for each drive present on the system. --- ### Basic Usage and Properties of the Drives Collection The returned `Drives` collection is a standard collection object. You can iterate through it using a `For Each...Next` loop to inspect individual drive properties, such as the drive letter, total size, free space, and drive type. #### Key Properties of the Drives Collection: * **Count**: Returns the number of items (drives) in the collection. * **Item(key)**: Returns a specific `Drive` object based on the specified drive letter (e.g., `Drives.Item("C")` or `Drives("C")`). --- ### Code Example: Listing All System Drives The following ASP/VBScript example demonstrates how to instantiate the `FileSystemObject`, retrieve the `Drives` collection, and loop through each drive to display its drive letter and type. ```asp <% Dim fso, driveList, d, driveTypeStr ' Create an instance of the FileSystemObject Set fso = Server.CreateObject("Scripting.FileSystemObject") ' Retrieve the Drives collection Set driveList = fso.Drives Response.Write("

Total number of drives detected: " & driveList.Count & "

") ' Iterate through each Drive object in the collection For Each d In driveList ' Determine the drive type Select Case d.DriveType Case 0: driveTypeStr = "Unknown" Case 1: driveTypeStr = "Removable" Case 2: driveTypeStr = "Fixed (Hard Drive)" Case 3: driveTypeStr = "Network Share" Case 4: driveTypeStr = "CD-ROM" Case 5: driveTypeStr = "RAM Disk" End Select Response.Write("Drive Letter: " & d.DriveLetter & "
") Response.Write("Drive Type: " & driveTypeStr & "
") ' Check if the drive is ready before accessing properties like VolumeName or FreeSpace If d.IsReady Then Response.Write("Volume Name: " & d.VolumeName & "
") Response.Write("Free Space: " & FormatNumber(d.FreeSpace / 1024 / 1024, 0) & " MB
") Else Response.Write("Drive is not ready (e.g., empty CD-ROM or card reader).
") End If Response.Write("
") Next ' Clean up objects Set driveList = Nothing Set fso = Nothing %> ``` --- ### Important Considerations 1. **The `IsReady` Property**: Always check the `IsReady` property of a `Drive` object before attempting to access properties like `TotalSize`, `FreeSpace`, `VolumeName`, or `FileSystemType`. Attempting to access these properties on removable drives that do not contain media (such as an empty CD-ROM drive or an empty USB card reader) will throw a runtime error. 2. **Network Drives**: Network drives will only appear in the collection if they are mapped to a drive letter on the server running the script. 3. **Permissions**: The web server process (e.g., IIS `IUSR` or `NetworkService` account) must have sufficient system permissions to query drive information, otherwise permission denied errors may occur.
← Met BuildpathProp Asperrorobject β†’