插入U盘怎样获取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;
end;

=========================================
  DRIVE_UNKNOWN = 0;
  {$EXTERNALSYM DRIVE_UNKNOWN}
  DRIVE_NO_ROOT_DIR = 1;
  {$EXTERNALSYM DRIVE_NO_ROOT_DIR}
  DRIVE_REMOVABLE = 2;
  {$EXTERNALSYM DRIVE_REMOVABLE}
  DRIVE_FIXED = 3;
  {$EXTERNALSYM DRIVE_FIXED}
  DRIVE_REMOTE = 4;
  {$EXTERNALSYM DRIVE_REMOTE}
  DRIVE_CDROM = 5;
  {$EXTERNALSYM DRIVE_CDROM}
  DRIVE_RAMDISK = 6;

阅读更多
文章标签: integer string path div
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭