jwalker14
asked on
How do you find the FileSize of a Text file
How do you find the FileSize of a TextFile when the FileSize function doesn't work on Text files?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Example without using Memo comp.....
---------------
procedure TForm1.Button2Click(Sender : TObject);
var
S : Real;
f : TextFile;
k,z : String;
begin
AssignFile(F, 'C:\windows\desktop\FindFu ncInWebBro wser.txt') ;
try
Reset(F);
Z := '';
while not EOF(F) do
begin
ReadLn(F, k);
Z := Z + K;
end;
S :=Length(Z) / 1024;
ShowMessage(Format('%.1f'' kb''', [s]));
finally
CloseFile(F);
end;
end;
---------------
Regards,
Viktor Ivanov
---------------
procedure TForm1.Button2Click(Sender
var
S : Real;
f : TextFile;
k,z : String;
begin
AssignFile(F, 'C:\windows\desktop\FindFu
try
Reset(F);
Z := '';
while not EOF(F) do
begin
ReadLn(F, k);
Z := Z + K;
end;
S :=Length(Z) / 1024;
ShowMessage(Format('%.1f''
finally
CloseFile(F);
end;
end;
---------------
Regards,
Viktor Ivanov
ASKER
This is a good solution but requires opening and closing the file. A co-worker was helping me on this this morning and suggested the following solutiong;
var
FileSize : integer;
DirRec : TSearchRec;
begin
FileName := 'C:\Windows\myfile.txt';
FindFirst(FileName, faAnyFile, DirRec);
FileSize := DirRec.Size;
end;
this could be either a function or procedure...
Your answer was very good and I appreciate the quick response...Thanks for all your help!
var
FileSize : integer;
DirRec : TSearchRec;
begin
FileName := 'C:\Windows\myfile.txt';
FindFirst(FileName, faAnyFile, DirRec);
FileSize := DirRec.Size;
end;
this could be either a function or procedure...
Your answer was very good and I appreciate the quick response...Thanks for all your help!
Well, I was thinking about this solution too, but had to realize that FindFirst/FindNext on a NT machine over a network needs a remarkable amount of time, so I suggested the other one.
Thanks and happy programming
Ciao, Mike
Thanks and happy programming
Ciao, Mike
ASKER
I was not aware of the degredation in performance on NT networks. Luckily were not using NT here...however, I appreciate your thoughts and thanks again for the help!
Jim Walker
Jim Walker
To see how much the a text file takes place try this.....
procedure TForm1.Button2Click(Sender
var
S : Real;
begin
S := Length(Memo1.text) / 1024;//Get the number in kb not bytes
ShowMessage(Format('%.1f''
end;
Hope this helps....
Regards,
Viktor Ivanov