Tamanho do arquivo

Delphi

28/10/2003

Tem como recuperar o tamanho do arquivo quando selecionado o mesmo?
Por exemplo:

Digamos que eu tenha selecionado o arquivo Teste.txt e o tamnho dele é 3kb, tem como recuperar esta informacao (3kb) dentro de um edit?


Marcela

Marcela

Curtidas 0

Respostas

Luineumann

Luineumann

28/10/2003

function TamArquivo(Arquivo: string): Integer;
begin
with TFileStream.Create(Arquivo, fmOpenRead or fmShareExclusive) do
try
Result := Size;
finally
Free;
end;
end;

Utilize a função assim:

procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:= inttostr(TamArquivo(´CAMINHO\NOMEDOARQUIVO´));
end;


GOSTEI 0
Rodrigo_rcp

Rodrigo_rcp

28/10/2003

var
nSize:integer;
nFile:Thandle;
StrSize:String;
begin
if OpenDialog1.Execute Then
  nFile:=CreateFile(PChar(OpenDialog1.FileName),0,File_Share_READ,nil,OPEN_EXISTING,0,0);
  nSize:=GetFileSize(nFile,nil);
  CloseHandle(nFile);
  SetLength(StrSize,20);
  Str(nSize,strSize);
  MessageBox(0,PChar(strSize),´Tamanho do arquivo´,MB_OK);
end;



GOSTEI 0
POSTAR