DelphiBasics
filesize
Function
Gives the size in records of an open file System unit
 function filesize(var FileHandle File;):Integer;
Description
The FileSize function gives the size in records of an open file.
 
Before this function can be used, the file must be assigned a handle by using AssignFile and opened using Append, Reset or ReWrite routines.
Notes
Because text files are normally variable in length, the number of records is not so useful. Use the low level routine GetFileSize to get the size in bytes, or FindFirst, FindNext routines, which return size and last modified date values of one or more files.
Related commands
DiskFreeGives the number of free bytes on a specified drive
DiskSizeGives the size in bytes of a specified drive
 Download this web site as a Windows program.




 
Example code : Get the size in records of a typed binary file
var
  myWord, myWord1, myWord2, myWord3 : Word;
  myFile : File of Word;

begin
  // Try to open the Test.cus binary file in write only mode
  AssignFile(myFile, 'Test.cus');
  ReWrite(myFile);

  // Before writing to the file, show the file size
  ShowMessage('File size = '+IntToStr(FileSize(myFile)));

  // Write a few lines of Word data to the file
  myWord1 := 123;
  myWord2 := 456;
  myWord3 := 789;
  Write(myFile, myWord1, myWord2, myWord3);

  // Before closing the file, show the new file size
  ShowMessage('File size now = '+IntToStr(FileSize(myFile)));

  // Close the file
  CloseFile(myFile);
end;
Show full unit code
  File size = 0
  File size now = 3
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page