I tried with Delphi XE and I got Not Responding while compiling. Does it work in your computer or is there something wrong with the function?
function Test(const FileName: string;
const Force: boolean = false): boolean;
var
IsAllowed: boolean;
begin
result := false;
if FileExists(FileName) then
begin
try
if (Force) then
begin
result := false;
exit;
end;
finally
if IsAllowed then
DeleteFile(FileName);
end;
try
result := true;
except
result := false;
end;
end;
end;