Results 1 to 2 of 2

Thread: [DELPHI] - Text File Size?

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    [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;

  2. #2

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    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
  •  



Click Here to Expand Forum to Full Width