# VBForums CodeBank > CodeBank - Other >  [DELPHI] - Text File Size?

## Madboy

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

----------


## Madboy

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).



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

----------

