I use very often the System.IOUtils units with the wonderful classes/records TPath, TDirectory and TFile. They are much more comfortable than the old functions from System.SysUtils like FindFirst etc..

But there is one method I’m really missing: It is the size of a file. For sure there are some workarounds but I think that this method belongs to TFile. That’s why I wrote a small helper class:

I will try to convince Marco or Jim to add this method to the next release. So stay tuned.

This entry was posted in C++-Builder, Delphi, RAD Studio 10.2 Tokyo, Uncategorized. Bookmark the permalink.

6 Responses to TFile.Size

  1. Stefan Glienke says:

    I will try to convince Marco or Jim to add this method to the next release. So stay tuned.

    No offense but I hope they refuse this implementation. Creating an object and doing several unnecessary operations on it to get the file size that probably every platform has an API for? Way to go to throw CPU cycles out of the window. I am not so deep into the WinAPI but there at least two ways to get this information without that overhead: GetFileSize and GetFileAttributesEx (while the former also needs the file to be opened which the second does not need).

  2. Peter says:

    I hope they will implement this.

  3. Stefan Glienke says:

    What I forgot to mention is that the implementation using TFileStream will fail if the file is already opened (try getting size of ParamStr(0) for example).

    So I came up with this implementation which is not only faster but does not fail on already opened files (I explicitly chose to not raise exceptions here but return -1 on failure):


  4. Pingback: Embarcadero MVP Roman Kassebaum offers up a TFile.Size function for System.IOUti… – HengeDK

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.