VHP Computing Group. Home Page.  
TechnologiesSpecialistsDownloadLinksSign GuestbookView Guestbook

23 March, 2001
Vladimir Trukhin
Senior Software Engineer
JSC "Votkinsk Hydroelectric Power Plant"
Fax: +7 (34241) 63297
E-mail:
vlt@votges.ru

Where is a CDROM?

The problem

Some program applications must read data from compact disks. Unconditionally, everybody knows the drive letter of CDROM that is mounted in his (her) computer. For example, the letter “E” conforms to my CDROM in the office computer. However, the home computer has compact disk with drive letter “D”, but my friend’s CDROM is mapped to letter “N”.

Unfortunately, Visual FoxPro 5.0 has no special functions to define a type of disk device. Nevertheless, VFP has function, which allows doing this by indirect way.

The solution

CDROM disk has a property which distinguishes its from hard disk or floppy disk. It always is full. It has no one bite of free space. This condition simplifies the problem.

IBM PC compatible computer can have up to 26 disk drives. Let’s try to check disk space for all drives. We’ll use DISKSPACE() function.

For the beginning we execute the following code:

local lnDriveNumber, lcDriveLetter
for lnDriveNumber=1 to 26
    lcDriveLetter=chr(lnDriveNumber+64)
    ? 'Free space of drive',lcDriveLetter,'=',;
    DISKSPACE(lcDriveLetter)
endfor

The result may be like the following:

Free space of drive A = 845824
Free space of drive B = -1
Free space of drive C = 577667072
Free space of drive D = 0
Free space of drive E = -1
Free space of drive F = -1
Free space of drive G = -1
… … …
… … …
Free space of drive X = -1
Free space of drive Y = -1
Free space of drive Z = -1

It can happen that there is a filled disk in the floppy disk drive. Then we’ll see the following:

Free space of drive A = 0
Free space of drive B = -1
Free space of drive C = 577667072
Free space of drive D = 0
Free space of drive E = -1
Free space of drive F = -1
Free space of drive G = -1
… … …
… … …
Free space of drive X = -1
Free space of drive Y = -1
Free space of drive Z = -1

The chances of it are very little, but we cannot neglect this case. Besides there are computers having more that one drive of CDROM.

I think there is no cause for despondency. Most programs operate with concrete data. If we'll build a list of devices similar to CDROM, our program will have been defining the device with needed data set.

Let's consider such example:

local lnDriveNumber, lcDriveLetter, llFile
for lnDriveNumber=1 to 26
    lcDriveLetter=chr(lnDriveNumber+64)
    llFile=.F.
    if DISKSPACE(lcDriveLetter)=0
        llFile=file(lcDriveLetter+':\ADOBE\ACROREAD.303\Pwnt303e.exe')
    endif
    ? 'Free space of drive',;
        lcDriveLetter,'=',;
        DISKSPACE(lcDriveLetter),iif(llFile,'OK!','')
endfor

The result will look approximately so:

Free space of drive A = 0
Free space of drive B = -1
Free space of drive C = 577667072
Free space of drive D = 0 OK!
Free space of drive E = 0
Free space of drive F = -1
Free space of drive G = -1
… … …
… … …
Free space of drive X = -1
Free space of drive Y = -1
Free space of drive Z = -1

You can download article in MS Word format. File is wscdrome.zip, size is 9 KB.
Also there is a Russian version of article.
File is wscdromr.zip, size is 11KB.


Home Page | Technologies | Specialists | Download | Links | Sign Guestbook | View Guestbook