Author: Jonas Bilinkevicius How to determine the size of a file Answer: Solve 1: You can use the type TSearchRec as follows: 1 function LoadSize(Path: string): integer; 2 var 3 Rec: TSearchRec; 4 begin 5 Result := 0; 6 if FindFirst(Path, faAnyFile, Rec) = 0 then 7 begin 8 Result := Rec.Size; 9 FindClose(Rec); 10 end; 11 end; Solve 2: 12 { ... } 13 var 14 fileInfo: _WIN32_FILE_ATTRIBUTE_DATA; 15 totalSize: Int64; 16 begin 17 GetFileAttributesEx(PChar(EdtPath.Text), GetFileExInfoStandard, @fileInfo); 18 totalSize := fileInfo.nFileSizeHigh shl 32 or fileInfo.nFileSizeLow; 19 end; Solve 3: 20 { ... } 21 var 22 SR: TSearchRec; 23 FileName: string; 24 r: integer; 25 begin 26 FileName := 'c:\winnt\system32\shell32.dll'; 27 r := FindFirst(FileName, faAnyFile, SR); 28 if r = 0 then 29 begin 30 Label1.Caption := Format('Size of %s is %d bytes (%0.1f Mb)', 31 [FileName, SR.Size, Sr.Size / 1000000]); 32 FindClose(SR); 33 end 34 else 35 Label1.Caption := 'File does not exist'; 36 end; Solve 4: 37 procedure TForm1.Button1Click(Sender: TObject); 38 var 39 hFile: THandle; 40 Size: Integer; 41 begin 42 if OpenDialog1.Execute then 43 begin 44 hFile := FileOpen(OpenDialog1.FileName, fmOpenRead or fmShareDenyNone); 45 Size := GetFileSize(hFile, nil); 46 {CloseHandle: use to close handle created with CreateFile which is 47 what FileOpen calls internally} 48 CloseHandle(hFile); 49 ShowMessage(Format('Size in bytes: %d', [Size])); 50 end; 51 end;