I need to get the size of a file through delphi 7 however I am getting an I / O error because the file is being used. (The file is an .exe and is open)
I have tried the following codes:
function TamanhoDoArquivo(arquivo: string): LongInt;
var
lArquivo: file of byte;
begin
with TFileStream.Create(arquivo, fmOpenRead or fmShareExclusive) do
try
Result := Size;
finally
Free;
end;
end;
And also:
function TamanhoDoArquivo(arquivo: string): LongInt;
var
lArquivo: file of byte;
begin
try
AssignFile(lArquivo, arquivo);
try
reset(lArquivo);
Result := FileSize(lArquivo);
finally
CloseFile(lArquivo)
end;
except
on E:Exception do
Showmessage('Erro');
end;
end;
Is there a way to get the size of .exe even though it is open? Thanks