错误c0000013
表示您正在访问的位置没有(可读)媒体。
请参阅:http: //msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx
因此,如果没有媒体,检查错误并继续前进是完全可以的。
您可以像这样获取所有 USB 设备的列表(请参阅:Delphi - 如何获取 USB 可移动硬盘和记忆棒的列表?)
procedure GetUsbDrives(List: TStrings);
var
DriveBits: set of 0..25;
I: Integer;
Drive: AnsiChar;
begin
List.BeginUpdate;
try
Cardinal(DriveBits) := GetLogicalDrives;
for I := 0 to 25 do
if I in DriveBits then
begin
Drive := Chr(Ord('a') + I);
if GetBusType(Drive) = BusTypeUsb then
List.Add(Drive);
end;
finally
List.EndUpdate;
end;
end;
如果您随后访问驱动器并收到错误,只需使用 try-except 来检测是否发生任何问题,请参阅:Delphi - 如何获取目录中所有文件的列表
function IsDevicePresent(DriveLetterOrPath: string): boolean;
const
success = 0;
Win_DeviceIsPresent = true;
Fail_DeviceNotPresent = false;
var
SearchRec: TSearchRec;
Drive: string;
begin
Drive:= ExtractFileDrive(DriveLetterOrPath);
try
Result:= (FindFirst(Drive, faAnyFile, SearchRec) = success);
except
Result:= Fail_DeviceNotPresent;
end; {try}
end;