大概有这些方法可以获得文件大小 FileSizeByName(需要引用IdGlobal单元) GetFileSize FileSize(不能获得正在使用的文件大小) FileSeek TFileStream.Size
下面是使用例子 1。FileSizeByName(需要引用IdGlobal单元) begin if OpenDialog1.Execute then begin ShowMessage(IntToStr(FileSizeByName(OpenDialog1.Filename))); end;
2。GetFileSize var FileHandle:integer; begin if OpenDialog1.Execute then begin FileHandle := FileOpen(OpenDialog1.FileName, 0); ShowMessage(IntToStr(GetFileSize(FileHandle, nil))); FileClose(FileHandle); end;
3。FileSize(不能获得正在使用的文件大小) var f: file; begin if OpenDialog1.Execute then begin AssignFile(f, OpenDialog1.FileName); Reset(f, 1); ShowMessage(IntToStr(FileSize(f))); CloseFile(f); end;
4。FileSeek var FileHandle:integer; begin if OpenDialog1.Execute then begin FileHandle := FileOpen(OpenDialog1.FileName, 0); ShowMessage(IntToStr(FileSeek(FileHandle,0,2))); FileClose(FileHandle); end;
5。TFileStream.Size var FS: TFileStream; begin if OpenDialog1.Execute then begin FS := TFileStream.Create(OpenDialog1.FileName, fmShareDenyNone); ShowMessage(IntToStr(FS.Size)); FS.Free; end;
另在IdGlobalProtocols中有个FileSizeByName()的函数。
|
请发表评论