Use VBScript to Check Partition Free Size

Environment
  • Microsoft Windows XP
Code
Function getFreeSpaceByGB(drvPath)
Dim oFSO, d, s
Set oFSO = CreateObject("Scripting.FileSystemObject")
s = -1

'Skip if it has not the drive
On Error Resume Next
   set d = oFSO.GetDrive(oFSO.GetDriveName(drvPath))
   If Err.Number = 0 Then
      hasDrive = d.IsReady

      'Check if it is available for use
      If hasDrive = True Then
         'For return in GB
         s = FormatNumber(d.FreeSpace / 1024 / 1024 / 1024, 0)
      Else
         s = -1
      End If
   End If

   getFreeSpaceByGB = s
End Function