delphi 判断文件是否已被占用

字体大小: 中小 标准 ->行高大小: 标准
function IsFileInUse(AName: string): boolean;
var
  hFileRes: HFILE;
begin
  Result := False;
  if not FileExists(AName) then exit;
  hFileRes := CreateFile(PChar(AName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  Result := hFileRes = INVALID_HANDLE_VALUE;
  if not Result then
    CloseHandle(hFileRes);
end;

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/70685.html