Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

checking free space on cdr media shows 0 bytes

0 views
Skip to first unread message

James

unread,
Aug 31, 2006, 2:11:17 PM8/31/06
to
anyone know why the filesystemobject's freespace property returns 0 bytes
free for my cdrom drive? theres a recordable cd in there with a few files on
it. when i open the drives properties in explorer it shows the correct
amount of freespace ~602MB's. but the filesystemobject's freespace property
allways returns 0. the following is my code:

Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(fso.GetDriveName("D:"))
s = d.freespace

set fso = nothing
set myfile = nothing
msgbox(s)


mr_unreliable

unread,
Sep 1, 2006, 1:40:34 PM9/1/06
to
hi James,

If you have wmi installed, you could try that,
(works for me).

--- <snip> ---
Dim wmi : Set oWMI = GetObject("winmgmts:")

for each Disk in oWMI.InstancesOf("Win32_LogicalDisk")

Select Case Disk.DriveType

Case 2 ' diskette drive
Case 3 ' hard drive
Case 5 ' cd
MsgBox("drive type: CD" & vbCrLf _
& "Capacity: " & Disk.Size & vbCrLf _
& "UsedSpace: " & CStr(Disk.Size - Disk.FreeSpace) &
vbCrLf _
& "Freespace: " & Disk.FreeSpace)

Case Else MsgBox("unrecognized drive type")
End Select
next ' next cpu

WScript.Quit
--- </snip> ---

and, if you know sql, you could select the cdrom out of the drive
collection directly.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

mr_unreliable

unread,
Sep 1, 2006, 1:55:00 PM9/1/06
to
This would be the more direct version:

--- <snip> ---
Dim wmi : Set oWMI = GetObject("winmgmts:")

wmiQuery = "select * from Win32_LogicalDisk where DriveType=5"
Set colCDs = oWMI.Execquery(wmiQuery)

if (colCDs.Count <= 0) then WScript.Quit ' no cd drives

for each Disk in colCDs

MsgBox("drive type: CD" & vbCrLf _
& "Capacity: " & Disk.Size & vbCrLf _
& "UsedSpace: " & CStr(Disk.Size - Disk.FreeSpace) & vbCrLf _
& "Freespace: " & Disk.FreeSpace)

next ' next cpu

WScript.Quit
--- </snip> ---

cheers, jw

James

unread,
Sep 1, 2006, 6:02:28 PM9/1/06
to
Thank You! freespace still shows 0 for me. but .size will help me cuz i know
that my CDs can only be like 700MB's so i can deduce how much is left. thank
ya!


"mr_unreliable" <kindlyReply...@notmail.com> wrote in message
news:O04yD8e...@TK2MSFTNGP03.phx.gbl...

mr_unreliable

unread,
Sep 2, 2006, 12:49:04 PM9/2/06
to
yet another script, this one using the win32_CDROMDrive class
to determime whether there is a cd (media) loaded into the
drive.

But the win32_CDROMDrive class does NOT have a freespace
property. And so the script shifts gears, and goes back
to the win32_LogicalDisk class to get the freespace.

Also, there is a bonus for you ultra-techie types. There
has been many postings concerning a minor point with wmi.
That is there seems to be no way to address a specific
item in a wmi collection with the "item" property, as in:
myCollection.Item(1).

In this script, you will find one example of that.

getCDROMFreespace.vbs.txt
0 new messages