Vbscript find free space on CD/DVD

I know that you can find the free space available for a hard disk using a vbscript, but is there a way to find the free space for a CD or DVD? I'm using the following code and keep getting 0.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set drive = objFSO.GetDrive(objFSO.GetDriveName("d:\"))

wscript.echo FormatNumber(drive.FreeSpace/1048576, 1)&"Mb"
Who is Participating?
old script I found.  It tells you the disk size of each drive.  just set it to your cd rom drive.  Once you close a session on a drive whatever the size of the burnt image is the total size of the partition on the disk.  It works on my machine.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For each objDisk in colDisks
	disksize = objDisk.size/1048576
    Wscript.Echo "Size: " & vbTab &  disksize    

Open in new window

That code will work for checking free space given whatever Drive your cd is in.  The problem is that once a CD session is closed it reports as 0 free space..  even if the cd itself is not at capacity.  I get the sense you are trying to write something to move data to a cd and programmatic tell you if you need to use more than one disk?
abgtempAuthor Commented:
Nah. Actually, I have a script that is pulling an ISO image from a directory, retrieving it's size and then burns the image to a CD. After the burn is complete, I want to do a validation that the image was burned successful by comparing original image size with the used space on the CD.
abgtempAuthor Commented:
Thanks. That worked for me. And I don't know why I was trying to get the free space originally since what I needed what the used space. I bumping the points up for the quick response and giving me an idea for later on if I do have to figure out how many disks to use.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.