VBScript Text Output

Associate
Joined
9 Sep 2008
Posts
40
Location
Moira, East Midlands
Salut!

First post - greetings to all and sundry.

I have a question for you VBScript guru's.

This code creates a text file with the amount of available free space, in bytes, left on the C:\ drive. I have set it so that it divides by 1024, and then again by 1024 to get MB.



Const ForWriting = 2

strComputer = "."

strFileName = "..\FreeSpace.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strFileName)

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")

For Each objDisk in colDisks
objFile.WriteLine ("freespace=") & ((objDisk.FreeSpace/1024)/1024)
Next

objFile.Close



I'm using a flash front end, which calls a batch file to run the VBScript - which then writes to a text file that flash finaly uses to display the output.

My problem is that the resultant number has around 5-8 decimal points, which I would like to have removed as part of the process.

Does anyone know of an amendment to the code that will do this? (similar to the Excel function that truncates down).

Thanks in advance. :cool:
 
What you want is the Fix function..

Code:
Const ForWriting = 2

strComputer = "."

strFileName = "..\FreeSpace.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strFileName)

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")

For Each objDisk in colDisks
objFile.WriteLine ("freespace=") & fix((objDisk.FreeSpace/1024)/1024)
Next

objFile.Close

Oh, and CLAIMED! :)
 
Back
Top Bottom