Board index » delphi » FileSize

FileSize

Hello,

I must know the length of a text file to use a progress bar. The function
FileSize gives the wrong result. What can I do to go around it?

Ydo Scheepstra

 

Re:FileSize


In article <01bd3bc6$9da5e3e0$62247d81@ydo>, Ydo Scheepstra
<I.J.SCHEEPS...@bureau.rug.nl> writes

Quote
>Hello,

>I must know the length of a text file to use a progress bar. The function
>FileSize gives the wrong result. What can I do to go around it?

You obviously didn't read the Help. There's an important note under
FileSize, and I quote:

Note
FileSize can't be used on a text file.

One way to get the size of a text file is to use something like
this:

function TextFileSize(const s : string);
var
  f : file of Char;
begin
  AssignFile(f, s);
  Reset(f);
  Result := FileSize(f);
  CloseFile(f);
end;

This is untested, but hopefully you get the idea. Also, if you *do*
use this code, at least try to make the function more robust.
--
Jeremy Collins

Re:FileSize


Quote
Ydo Scheepstra wrote:

> Hello,

> I must know the length of a text file to use a progress bar. The function
> FileSize gives the wrong result. What can I do to go around it?

> Ydo Scheepstra

FileSize retrieve the bad result may be because it gives the record
count. Which type is your file ? (File of Byte or File of TCustomer ?).

I hope this questions will help you.

Frdric GUILLIEN

Re:FileSize


Quote
Ydo Scheepstra wrote:

> Hello,

> I must know the length of a text file to use a progress bar. The function
> FileSize gives the wrong result. What can I do to go around it?

procedure TForm1.Button1Click(Sender: TObject);
{By using SearchRec, you don't have to Open (Reset) the file
 before being able to get it's size.}
var
  Attrib: Word;
  Sr: TSearchRec;
begin
  FindFirst('C:\AUTOEXEC.BAT',faAnyFile ,Sr);
  Label1.Caption:=IntToStr(Sr.Size);
end;

Markku Nevalainen

Other Threads