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 windows xp下屏蔽ctrl_alt_del键的方法

Delphi tstringlist删除重复项

Delphi md5加密base64加解密

Delphi的tfilestream 内存流

Delphi findfiles获取目录下所有文件

Delphi 变量和常量

Delphi 取时间戳

Delphi 遍例一个外部程序中所有的类名

Delphi 通过jet引擎压缩和修复access数据库

idhttpserver允许跨域访问

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



打赏

取消

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

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

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

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

评论

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