Forum Discussion
tristaanogre
15 years agoEsteemed Contributor
I don't know of a particular method to determine if a file is in use or not. However, what you could do is try and open the file and trap an exception using aqFile.OpenTextFile such as the following DelphiScript code.
function FileInUse(FilePath): Boolean;
{
If the file is in use, an exception is raised resulting in the function returning
true. If not, the file is attempted to be closed and the result of the function
is set to the opposite of whether or not the file was able to be closed
}
var
MyFileObject;
begin
try
MyFileObject := aqFile.OpenTextFile(FilePath, aqFile.faReadWrite, aqFile.ctAnsi, FALSE);
Result := not MyFileObject.Close;
except
Result := TRUE;
end;
end;
Related Content
Recent Discussions
- 2 days agoGane195