但此函数有一问题,如过目录所包含的磁盘不存在就会出错:
所以要判断一下:
function DiskDriverReady(FileName:String):Boolean; // 判断磁盘
type
tp= ^ Char;
var
sTmp :String;
ptp :tp;
pTmp :Char;
ErrorMode :Word;
DiskDirver:Byte;
begin
Result:= False ;
Try
sTmp:= ExtractFileDrive(FileName);
if sTmp='' then Exit;
if sTmp[Length(sTmp)]<>':' then Exit;
sTmp:= UpperCase(Stmp[1]);
ptp:= tp(sTmp);
pTmp:= ptp^;
DiskDirver:= ord(pTmp)- 64 ;
if DiskDirver >26 then Exit;
ErrorMode:=SetErrorMode(SEM_FAILCRITICALERRORS);
if DiskFree(DiskDirver) <> -1 then Result:= True;
SetErrorMode(ErrorMode);
except
Exit;
end;
end;
function FileExistFlag(FileName:String):Boolean;// 判断目录
begin
if DiskDriverReady(FileName) then
Result:= FileExists(FileName)
else
Result:= False;
end;