UINT GetDriveType(
LPCTSTR lpRootPathName //根目录的路径名
);
参数lpRootPathName为一个包含需要测试的驱动器根目录的名称,如果为NULL,返回当前目录的根目录进行操作
返回值的含义:
0 无法检测驱动器的类型
1 根目录无效
DRIVE_REMOVEABLE 可移动驱动器
DRIVE_FIXED 不可移动驱动器
DRIVE_REMOTE 网络驱动器
DRIVE_CDROM 光驱
DRIVE_RAMDISK 虚拟驱动器
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
result:integer;
driver:pchar;
begin
result:=getdrivetype(pchar(trim(edit1.text)));
case result of
drive_removable:edit1.Text:='可移动驱动器';
drive_fixed: edit1.text:='不可移动驱动器';
drive_remote: edit1.Text:='网络驱动器';
drive_cdrom: edit1.text:='cd-rom驱动器';
drive_ramdisk: edit1.Text:='虚拟驱动器';
else
edit1.Text:='无效的驱动器符号';
end;
end;
end.