检查驱动器A中磁盘是否有效......
3.检查驱动器A中磁盘是否有效
type
TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES);
……
function DriveState (driveletter: Char) : TDriveState;
var
mask: String[6];
sRec: TSearchRec;
oldMode: Cardinal;
retcode: Integer;
begin
oldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
mask:= "?:\*.*";
mask[1] := driveletter;
{$I-}
retcode := FindFirst (mask, faAnyfile, Srec);
FindClose(Srec);
{$I+}
case retcode of
0 : Result := DSDISK_WITHFILES; //磁盘有文件
-18 : Result := DSEMPTYDISK; //好的空磁盘
-21, -3: Result := DSNODISK; //NT,Win31的错误代号
else
Result := DSUNFORMATTEDDISK;
end;
SetErrorMode(oldMode);
end;
查看本文来源