Preciso pegar o tamanho de um arquivo pelo delphi 7 porém estou recebendo erro de I/O por que o arquivo está sendo usado. (O arquivo é um .exe e está aberto)
Já tentei os seguintes códigos:
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;
E também:
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;
Há alguma forma de pegar o tamanho do .exe mesmo que o mesmo esteja aberto? Obrigado