delphi 判断文件是否被占用


本文整理自网络,侵删。

 function IsFileInUse(fName: string) : boolean;
var
  HFileRes: HFILE;
begin
  Result := False;
  if not FileExists(fName) then begin
    Exit;
  end;

  HFileRes := CreateFile(PChar(fName)
    ,GENERIC_READ or GENERIC_WRITE
    ,0
    ,nil
    ,OPEN_EXISTING
    ,FILE_ATTRIBUTE_NORMAL
    ,0);

  Result := (HFileRes = INVALID_HANDLE_VALUE);

  if not(Result) then begin
    CloseHandle(HFileRes);
  end;
end;

相关阅读 >>

Delphi根据进程pid等待进程结束或者结束进程

Delphi用mapfileandchecksum 函数检测 exe 或 dll 是否被修改

Delphi 反转字符串方法2

Delphi 完美的线程注入和卸载

Delphi 如何在stringgrid中嵌入控件,如按钮等等

Delphi版本号检测判断

Delphi idsmtp发送邮件的问题

Delphi ifileoperation替换shfileoperation

Delphi 纯window系统api实现的ssl客户端

Delphi 的内存操作函数(3): 给结构体指针分配内存

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...