-
Jun 21st, 2005, 01:05 PM
#1
Thread Starter
Supreme User
[DELPHI] - Text File Size?
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec: TSearchRec;
begin
if OpenDialog1.Execute then
if FindFirst(OpenDialog1.FileName, faAnyFile, SearchRec) = 0 then
Label1.Caption := FloatToStrF(SearchRec.Size/1048576, ffFixed, 7, 2)+' MB';
FindClose(SearchRec);
end;
-
Jul 14th, 2005, 09:25 AM
#2
Thread Starter
Supreme User
Re: [DELPHI] - Text File Size?
I found that the above code was not really necessary as Text documents dont really come in Mega Bytes. So, using this snippet will get the Kilobyte of a document (or any file actually).
Code:
function Get_File_Size1(sFileToExamine: string; bInKBytes: Boolean): string;
var
FileHandle: THandle;
FileSize: LongWord;
d1: Double;
i1: Int64;
begin
FileHandle:= CreateFile(PChar(sFileToExamine),
GENERIC_READ,
0, {exclusive}
nil, {security}
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
FileSize:= GetFileSize(FileHandle, nil);
Result:= IntToStr(FileSize);
CloseHandle(FileHandle);
if bInKbytes = True then
begin
if Length(Result) > 3 then
begin
Insert('.', Result, Length(Result) - 2);
d1:= StrToFloat(Result);
Result:= IntToStr(round(d1)) + 'KB';
end
else
Result:= '1KB';
end;
end;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|