Step 2—Check Free Disk Space

Hard disks with capacities measured in the tens of gigabytes are commonplace nowadays, so disk space is much less of a problem than it used to be. Still, you need to keep track of how much free space you have on your disk drives, particularly the Windows XP system drive, which usually stores the virtual memory page file.

One way to check disk free space is to view My Computer using the Details view, which includes columns for Total Size and Free Space, as shown in Figure 12-2. Alternatively, right-click the drive in Windows Explorer and then select Properties. The disk’s total capacity as well as its current used and free space appear on the General tab of the disk’s property sheet.

Display My Computer in Details view to see the total size and free space on your system’s disks.

Figure 12-2. Display My Computer in Details view to see the total size and free space on your system’s disks.

Here’s a VBS script that displays the status and free space for each drive on your system:

Option Explicit
Dim objFSO, colDiskDrives, objDiskDrive, strMessage

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Get the collection of disk drives
Set colDiskDrives = objFSO.Drives

' Run through the collection
strMessage = "Disk Drive Status Report" & vbCrLf & vbCrLf
For Each objDiskDrive in colDiskDrives

    ' Add the drive letter to the message
    strMessage = strMessage & "Drive: " _
& objDiskDrive.DriveLetter & vbCrLf

    ' Check the drive status
    If objDiskDrive.IsReady = True Then

        ' If it's ready, add the status and the free space to the message
        strMessage = strMessage & "Status: Ready" & vbCrLf
        strMessage = strMessage & "Free space: " & objDiskDrive.FreeSpace
        strMessage = strMessage & vbCrLf & vbCrLf
    Else

        ' Otherwise, just add the status to the message
        strMessage = strMessage & "Status: Not Ready" & vbCrLf & vbCrLf
    End If
Next

' Display the message
Wscript.Echo strMessage

This script creates a FileSystemObject and then uses its Drives property to return the system’s collection of disk drives. Then a For Each...Next loop runs through the collection, gathering the drive letter, the status, and, if the disk is ready, the free space. It then displays the drive data, as shown in Figure 12-3.

The script displays the status and free space for each drive on your system.

Figure 12-3. The script displays the status and free space for each drive on your system.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.150.41