Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking disk freespace

Status
Not open for further replies.

vbcdor

Technical User
Jan 27, 2004
39
US
Hi,I'm fairly new to VBScript and can't figure out what is wrong with the statement below. Basically, I'm trying to check for available freespace on two different drives and I plan on sending an email if the freespace is below a certain amount for each drive. I stuck in some Wscript.Echo commands to make sure the values were what I thought they were, and sure enough they were. My C: drive is 0.598 and F is 0.065, but when I execute this code, "str" is always set to null. It never executes the then clause on either if statement. What is wrong with my If statement?

Code:
str = ""
set oFs = WScript.CreateObject("Scripting.FileSystemObject")
set oDrives = oFs.Drives
strComputerName = GetCurrentComputerName 
For Each oDrive In oDrives
  Select Case oDrive.DriveType
  Case Fixed
    WScript.Echo oDrive.DriveLetter & " " & (Round (oDrive.FreeSpace / oDrive.TotalSize, 3)) 
    If oDrive.DriveLetter= C And Round(oDrive.FreeSpace / oDrive.TotalSize, 3) < 0.7 Then
      str = str & strComputerName & "    " & oDrive.DriveLetter & "    " & Round(oDrive.FreeSpace / oDrive.TotalSize, 2) & vbCrLf
    End If
    If oDrive.DriveLetter= F And Round(oDrive.FreeSpace / oDrive.TotalSize, 3) < 0.10 Then
      str = str & strComputerName & "    " & oDrive.DriveLetter & "    " & Round(oDrive.FreeSpace / oDrive.TotalSize, 2) & vbCrLf
    End If
  WScript.Echo 'str = ' str
  End Select
Next
 
Perhaps this ?
If oDrive.DriveLetter=[!]"[/!]C[!]"[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
well, it was a good thought. I just tried it and it didn't work.
 
There are lots of issues with your script but lets start with what are the drive letters of the drives you want to check free space for ?
 
Tip: use the Option Explicit instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Actually, I stand corrected. I think it is working now. The WScript.Echo 'str = ' str is still displaying nothing (null), but I am receiving the email when I am suppose to.

thanks
 
WScript.Echo [!]"[/!]str = [!]" &[/!] str

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top