计算机二级DELPHI技巧:DELPHI获取U盘盘符代码
http://www.itjxue.com 2015-07-17 00:54 来源:未知 点击次数:
使用delphi程序实现U盘盘符的获取其实不是很难,不过对于新手来说可能有点困难,把代码贴出来,供大家学习
procedure TForm1.FormCreate(Sender: TObject);
var
buf:array [0..MAX_PATH-1] of char;
m_Result:Integer;
i:Integer;
str_temp:string;
begin
m_Result:=GetLogicalDriveStrings(MAX_PATH,buf);
for i:=0 to (m_Result div 4) do
begin
str_temp:=string(buf[i*4]+buf[i*4+1]+buf[i*4+2]);
if getdrivetype(pchar(str_temp)) = DRIVE_REMOVABLE then
begin
showmessage(str_temp+’盘为U盘’);
ListBox1.Items.Add(str_temp);
end;
end;