判断文件是否已被占用

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; 



摘自 橙子

你可能感兴趣的:(文件)