看看FileExists的实现如下:<br><br>function FileAge(const FileName: string): Integer;<br>var<br> Handle: THandle;<br> FindData: TWin32FindData;<br> LocalFileTime: TFileTime;<br>begin<br> Handle := FindFirstFile(PChar(FileName), FindData);<br> if Handle <> INVALID_HANDLE_VALUE then<br> begin<br> Windows.FindClose(Handle);<br> if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then<br> begin<br> FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);<br> if FileTimeToDosDateTime(LocalFileTime, LongRec(Result).Hi,<br> LongRec(Result).Lo) then Exit;<br> end;<br> end;<br> Result := -1;<br>end;<br><br>function FileExists(const FileName: string): Boolean;<br>begin<br> Result := FileAge(FileName) <> -1;<br>end;<br><br>----------------------------------<br>你可以重写这个 FileExists,使用 SearchPath 代替 FindFirstFile/FindClose!<br><br>如下:<br>function MyFileExists(const FileName: string): Boolean;<br>var<br> P, F: string;<br> Buf: array[0..255] of Char;<br> FP: PChar;<br> N: Integer;<br>begin<br> try<br> P:= ExtractFilePath(FileName);<br> F:= ExtractFileName(FileName);<br> N:= SearchPath(PChar(P), PChar(F), nil, 256, Buf, FP);<br> Result:= N<>0;<br> except<br> end;<br>end;<br><br>下面是我做的测试,请参考:<br><br>function MyFileExists(const FileName: string): Boolean;<br>var<br> P, F: string;<br> Buf: array[0..255] of Char;<br> FP: PChar;<br>begin<br> try<br> P:= ExtractFilePath(FileName);<br> F:= ExtractFileName(FileName);<br> Result:= SearchPath(PChar(P), PChar(F), nil, 256, Buf, FP) <> 0;<br> except<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> S: string;<br>begin<br> if OpenDialog1.Execute then<br> begin<br> S:= 'Not Existed!';<br> if MyFileExists(OpenDialog1.FileName) then<br> S:= 'Existed!';<br><br> ShowMessage(S);<br> end;<br>end;<br>