unit Unit1;
int erface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function DriveExists(Drive: Byte): boolean;
var
LogDrives: set of 0 .. 25;
begin
Integer(LogDrives) := GetLogicalDrives;
Result := Drive in LogDrives;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
D: Byte;
begin
for D := 0 to 25 do
if DriveExists(D) then
v begin ListBox1.Items.Add(Chr(D + $41));
end;
end;
function CheckDriveType(Drive: Byte): String;
var
DriveLetter: Char;
DriveType: UInt;
begin
DriveLetter := Char(Drive + $41);
DriveType := GetDriveType(PChar(DriveLetter + ':\'));
Case DriveType of
0:
Result := 'Тип устройства не определен';
1:
Result := 'Корневой каталог не существует';
DRIVE_REMOVABLE:
Result := 'Дисковод со сменным носителем';
DRIVE_FIXED:
Result := 'Дисковод с несменным носителем';
DRIVE_REMOTE:
Result := 'Сетевое устройство';
DRIVE_CDROM:
Result := 'Привод CD-ROM';
DRIVE_RAMDISK:
Result := 'Диск, созданный в памяти (RAM)';
else
Result := 'Не определен'
end;
end;
function GetFileSysName(Drive: Byte): String;
var
DriveLetter: Char;
NoMatter: Cardinal;
FileSysName: Array [0 .. MAX_PATH] of Char;
begin
DriveLetter := Char(Drive + $41);
GetVolumeInformation(PChar(DriveLetter + ':\'), nil, 0, Nil, NoMatter,
NoMatter, FileSysName, SizeOf(FileSysName));
Result := FileSysName;
end;
function GetFileSysLen(Drive: Byte): Integer;
var
DriveLetter: Char;
NoMatter: Cardinal;
FileSysName: Array [0 .. MAX_PATH] of Char;
begin
DriveLetter := Char(Drive + $41);
GetVolumeInformation(PChar(DriveLetter + ':\'), nil, 0, Nil, NoMatter,
NoMatter, FileSysName, SizeOf(FileSysName));
Result := SizeOf(FileSysName);
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var
Drive: Byte;
begin
with ListBox1 do
Drive := ord(Items[ItemIndex][1]) - $41;
Label1.Caption := 'Номер устройства = ' + intToStr(Drive);
Label2.Caption := CheckDriveType(Drive);
Label3.Caption := 'Название файловой системы - ' + GetFileSysName(Drive);
Label4.Caption := 'Длина имени файла = ' + intToStr(GetFileSysLen(Drive));
end;
end.