Chapter 53: ASP Drive Object
ASP Drive Object.
This is not a separate W3Schools lesson (they mention it very briefly inside the “ASP FileSystemObject” and “ASP Drives” sections), but it is one of the most practical sub-objects you get when working with FileSystemObject (FSO) in real Classic ASP code — especially when you need to work with disk drives, free space, file system type, volume labels, or check if a drive is ready.
I will explain it like your favorite teacher who actually used Drive objects in production Classic ASP sites (mostly for logging disk space warnings, validating upload paths, or building admin file browsers) — slowly, clearly, with real working examples, good habits, common mistakes, security notes, and the exact patterns you would see in legacy Indian business/intranet/ERP/government code that still runs this way in 2026.
1. What is the Drive Object?
The Drive object is not created directly with Server.CreateObject.
You get a Drive object in one of two ways:
- From the FileSystemObject.Drives collection (loop over all drives)
- From FileSystemObject.GetDrive(driveLetterOrPath)
It represents one physical or logical drive on the server (C:, D:, E:, network mapped drives, etc.) and gives you information about:
- Drive letter
- Volume label (name)
- File system type (NTFS, FAT32, etc.)
- Total size / free space
- Whether the drive is ready (not CD-ROM without disc, not disconnected network drive)
- Root folder, serial number, etc.
Very important: Drive object is read-only — you cannot format drives, change labels, or write data through it. It is information only.
2. How to Get Drive Objects
Way 1 – Loop over all drives (most common real use)
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <body> <h2>Server Drives Information (ASP Drive Object)</h2> <table border="1" cellpadding="5"> <tr> <th>Drive Letter</th> <th>Label</th> <th>File System</th> <th>Total Size (GB)</th> <th>Free Space (GB)</th> <th>Ready?</th> </tr> <% Dim fso, drive, drives Set fso = Server.CreateObject("Scripting.FileSystemObject") Set drives = fso.Drives For Each drive In drives Response.Write "<tr>" Response.Write "<td>" & drive.DriveLetter & ":</td>" If drive.IsReady Then Response.Write "<td>" & Server.HTMLEncode(drive.VolumeName) & "</td>" Response.Write "<td>" & drive.FileSystem & "</td>" ' Sizes in GB (divide by 1073741824 = 1024^3) Dim totalGB, freeGB totalGB = Round(drive.TotalSize / 1073741824, 2) freeGB = Round(drive.FreeSpace / 1073741824, 2) Response.Write "<td>" & totalGB & "</td>" Response.Write "<td>" & freeGB & "</td>" Response.Write "<td style='color:green;'>Yes</td>" Else Response.Write "<td colspan='4' style='color:red;'>Not Ready (e.g. CD-ROM empty or network disconnected)</td>" End If Response.Write "</tr>" Next Set drives = Nothing Set fso = Nothing %> </table> </body> </html> |
Typical output (on a real Windows server):
| Drive Letter | Label | File System | Total Size (GB) | Free Space (GB) | Ready? |
|---|---|---|---|---|---|
| C: | Windows | NTFS | 237.5 | 89.2 | Yes |
| D: | Data | NTFS | 931.5 | 612.4 | Yes |
| E: | (empty) | — | — | No |
2. Way 2 – Get One Specific Drive
|
0 1 2 3 4 5 6 |
<% Dim fso, driveC Set fso = Server.CreateObject("Scripting.FileSystemObject") ' Can use drive letter OR full path Set driveC = fso.GetDrive("C:") If driveC.IsReady Then Response.Write "<p>Drive C: Label = " & Server.HTMLEncode(driveC.VolumeName) & "</p>" Response.Write "<p>File System = " & driveC.FileSystem & "</p>" Response.Write "<p>Total size = " & Round(driveC.TotalSize / 1073741824, 2) & " GB</p>" Response.Write "<p>Free space = " & Round(driveC.FreeSpace / 1073741824, 2) & " GB</p>" Response.Write "<p>Serial Number = " & driveC.SerialNumber & "</p>" Else Response.Write "<p>Drive C: is not ready.</p>" End If Set driveC = Nothing Set fso = Nothing %> |
3. Real-World Production Patterns (What You Actually Saw)
Pattern 1 – Disk Space Warning (Very Common in Admin Pages)
|
0 1 2 3 4 5 6 |
<% Dim fso, drive, freeGB Set fso = Server.CreateObject("Scripting.FileSystemObject") Set drive = fso.GetDrive("C:") If drive.IsReady Then freeGB = Round(drive.FreeSpace / 1073741824, 2) If freeGB < 5 Then Response.Write "<div style='color:red; font-weight:bold; padding:15px; border:2px solid red;'>" Response.Write "WARNING: Only " & freeGB & " GB free on C: drive!<br>" Response.Write "Server may stop working soon!" Response.Write "</div>" End If End If Set drive = Nothing Set fso = Nothing %> |
Pattern 2 – Validate Upload Path (Security Check)
|
0 1 2 3 4 5 6 |
<% Dim uploadFolder, fso, driveLetter uploadFolder = Server.MapPath("/uploads/") Set fso = Server.CreateObject("Scripting.FileSystemObject") ' Extract drive letter from path driveLetter = Left(uploadFolder, 2) ' "C:" Dim drive Set drive = fso.GetDrive(driveLetter) If Not drive.IsReady Then Response.Write "<p style='color:red;'>Upload drive is not ready!</p>" Response.End End If If drive.FreeSpace < 100000000 Then ' < 100 MB Response.Write "<p style='color:red;'>Not enough free space for upload!</p>" Response.End End If ' Proceed with upload... %> |
4. Security & Best Practice Warnings (Critical in 2026)
- Never expose Drive information (free space, paths) to regular users — only admin pages
- Server.MapPath → always use it — never trust user input for paths
- Disable FSO or block write access in IIS if not needed — many classic ASP sites were hacked via path traversal + FSO
- Use On Error Resume Next around GetDrive — some servers hide drives or have permission issues
- VolumeName, SerialNumber — useful for fingerprinting server, but rarely used now
5. Teacher Summary – ASP Drive Object in Classic ASP
ASP Drive Object is:
- A read-only info object you get from fso.Drives collection or fso.GetDrive(driveLetterOrPath)
- Represents one drive (C:, D:, network drive, etc.)
- Main properties: DriveLetter, VolumeName, FileSystem, TotalSize, FreeSpace, IsReady, SerialNumber
- Used for: disk space monitoring, validating paths, admin dashboards, logging server health
- No write/create/delete methods — only information
- Always check IsReady before reading sizes
- Always use Server.MapPath for paths
- Very useful in admin tools, but almost never shown to regular users
This is how serious Classic ASP sites monitored disk space, validated upload locations, and added admin health checks — and many legacy Indian systems still use exactly this Drive object pattern in 2026.
Next class?
- Want a full admin disk space dashboard example?
- Or how to combine Drive + TextStream (log only if free space > threshold)?
- Or secure FSO/Drive usage (permissions, blocking)?
- Or move to the next W3Schools topic (ASP TextStream again or ASP Cookies)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
