Board index » cppbuilder » detect hard drive?

detect hard drive?


2005-11-10 10:08:03 PM
cppbuilder83
My problem is that on our old systems the D: drive is a hard drive and
we use it to store data but on the new systems the D: drive is a CD/DVD
drive. I would like to detect if the D: drive is a hard drive and could
be used for data storage. I have tried using "DiskFree() and
directoryExist() but when I do I get a message saying "There is no disk
in the drive...". How can I detect if the D: drive is a hard drive?
 
 

Re:detect hard drive?

Look at API: GetDriveType()
Also look at API: GetLogicalDriveStrings()
This is the code that I use to find first CD ROM
drive, and you can modify it to accomodate your
needs...
AnsiString GetFirstCdRomDrive()
{
unsigned long r;
char Drives[129];
char* pDrive;
AnsiString Result = "";
r = GetLogicalDriveStrings( sizeof( Drives ), Drives );
if ( r == 0 ) return ( Result );
if ( r>sizeof( Drives ) )
return( Result );
pDrive = &Drives[0]; // Point to the first drive
while ( *pDrive != NULL )
{
if ( GetDriveType( pDrive ) == DRIVE_CDROM )
return ( UpperCase ( (char)*pDrive ) + ":\\" );
pDrive += 4; // Point to the next drive
}
return( "" );
}
--
Best regards,
Vladimir Stefanovic
 

Re:detect hard drive?

Thank you.
Vladimir Stefanovic wrote:
Quote
Look at API: GetDriveType()

Also look at API: GetLogicalDriveStrings()

This is the code that I use to find first CD ROM
drive, and you can modify it to accomodate your
needs...

AnsiString GetFirstCdRomDrive()
{
unsigned long r;
char Drives[129];
char* pDrive;
AnsiString Result = "";

r = GetLogicalDriveStrings( sizeof( Drives ), Drives );

if ( r == 0 ) return ( Result );
if ( r>sizeof( Drives ) )
return( Result );

pDrive = &Drives[0]; // Point to the first drive

while ( *pDrive != NULL )
{
if ( GetDriveType( pDrive ) == DRIVE_CDROM )
return ( UpperCase ( (char)*pDrive ) + ":\\" );
pDrive += 4; // Point to the next drive
}

return( "" );
}

--
Best regards,
Vladimir Stefanovic
 

{smallsort}