エラー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;