我用下面的方法老是出错。请高手指点。
size:longint s:string; F:TStrings; F:=TStringList.Create;
F.LoadFromFile('c:\test\1.txt');
s:=f.Text;
size := FileSize(f); //提示类型不匹配 ;
// 用size:=filesize(s) 也不行。
s:=inttostr(size);
showmessage(s);到底该怎么才能得到文件有几个字符呢?
size:longint s:string; F:TStrings; F:=TStringList.Create;
F.LoadFromFile('c:\test\1.txt');
s:=f.Text;
size := FileSize(f); //提示类型不匹配 ;
// 用size:=filesize(s) 也不行。
s:=inttostr(size);
showmessage(s);到底该怎么才能得到文件有几个字符呢?
sr: TSearchRec;begin if FindFirst('c:\1.txt',faAnyFile,sr) = 0 then showmessage(IntToStr(sr.Size)); FindClose(sr);end;
function FileSizeByName(const AFilename: string): Int64;
begin
with TFileStream.Create(AFilename, fmOpenRead or fmShareDenyNone) do
try
Result := Size;
finally
Free;
end;
end;
http://community.csdn.net/Expert/topic/2910/2910006.xml?temp=.9839594
procedure TForm1.Button1Click(Sender: TObject);
var
stm:Tmemorystream;
begin
stm:=Tmemorystream.Create ;
stm.LoadFromFile('C:/mmm.txt');
showmessage(inttostr(stm.Size));
end;
你看看是否可以。
var
f: file of Byte;
size: Longint;
begin
AssignFile(f, 'E:\项目\程序退出.txt');
Reset(f); size := FileSize(f);
showmessage(inttostr(size));
end;
你用这些代码试一下
我测试过