判断文件是否已被占用

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; 

摘自 橙子

posted @ 2012-02-05 22:47  海利鸟  阅读(399)  评论(0编辑  收藏  举报