|
Borland C ++ Builder FAQ
|
||
| The content | The last update: 12/12/2008 | |
|
To receive the list of disks and their parameters The author: OlegGG
int n;
bool Flag;
DWORD dr = GetLogicalDrives ();//function returns a bit mask
for (int x=0; x <26; x ++)//it is passable a cycle on bits
{
n = ((dr>> x) &1);//we learn value of current bit
if (n)//if unit - the disk with number x is
{
AnsiString dl = AnsiString ((char) (65+x));//we receive a disk letter
AnsiString path = AnsiString ((char) (65+x)) + ": \\";
AnsiString out = "Disk" + dl + "\n";
Whether//here we learn the device is ready
WORD OldErrorMode;
OldErrorMode = SetErrorMode (SEM_FAILCRITICALERRORS);//we remove show of errors
bool ready = DirectoryExists (path);//пытаемcя to open a root directory
SetErrorMode (OldErrorMode);//we recover an ancient regime of show of errors
if (ready)
{
UINT drive_type = GetDriveType ((dl + ": \\").c_str ());//we learn disk type
out + = "\nTip a disk:";
if (drive_type == DRIVE_REMOVABLE) out + = "REMOVABLE";
else if (drive_type == DRIVE_FIXED) out + = "FIXED";
else if (drive_type == DRIVE_REMOTE) out + = "REMOTE";
else if (drive_type == DRIVE_CDROM) out + = "CD-ROM";
else if (drive_type == DRIVE_RAMDISK) out + = "RAMDISK";
else out + = "НЕИЗВЕСТНЫЙ_ТИП\n";
//if it HDD - заприашиваем the information on it
if (drive_type == DRIVE_FIXED)
{
unsigned __ int64 FreeBytesAvailable;
unsigned __ int64 TotalNumberOfBytes;
unsigned __ int64 TotalNumberOfFreeBytes;
char drive_label [30];
char drive_fat [30];
DWORD drive_sn;
DWORD drive_name_size = sizeof (drive_label);
//it is obtained the data about the sizes
Flag =:: GetDiskFreeSpaceEx (path.c_str (),
(PULARGE_INTEGER) &FreeBytesAvailable,
(PULARGE_INTEGER) &TotalNumberOfBytes,
(PULARGE_INTEGER) &TotalNumberOfFreeBytes
);
if (Flag)
{
out + = "\nSvobodno on a disk:" + AnsiString (TotalNumberOfFreeBytes) + "\n";
out + = "All on a disk:" + AnsiString (TotalNumberOfBytes) + "\n";
}
else
{
out + = "the Error in GetDiskFreeSpaceEx\n";
}
//we receive a label, серинийный number and so forth
Flag = GetVolumeInformation (path.c_str (),
drive_label,
sizeof (drive_label),
&drive_sn,
&drive_name_size,
NULL,
drive_fat,
sizeof (drive_fat)
);
if (Flag)
{
out + = "\nMetka volumes:" + AnsiString (drive_label) + "\n";
out + = "Ser.nomer:" + AnsiString (drive_sn) + "\n";
out + = "File system:" + AnsiString (drive_fat) + "\n";
}
else
{
out + = "the Error in GetVolumeInformation\n";
}
}
}
else
{
out + = "IS NOT READY";
}
ShowMessage (out);
}
}
|