[fpc-devel] Determin file size - how?

Tomas Hajny XHajT03 at hajny.biz
Thu Dec 15 00:07:41 CET 2011


On 14 Dec 11, at 23:42, Michael Van Canneyt wrote:
> On Wed, 14 Dec 2011, Hans-Peter Diettrich wrote:
> 
> > I wonder how to obtain the size of an file on disk. The only function I could 
> > find so far is FileSize, which requires an open File, but nothing for an file 
> > name :-(
> >
> > ATM FileSize(TEXT) would help, too, but FileSize only accepts an FILE, not 
> > TEXT :-(
> >
> > FpFStat() seems unavailable on Windows :-(
> >
> > FindFirst may be usable, but is very clumsy for this simple request.
> 
> Nevertheless, it is the only option.
> 
> For example FileAge also calls FindFirst.

I don't think that it's really the only option in general - at least 
DOS-like platforms (DOS, OS/2, MS Windows) usually retrieve the size  
by a Seek API call specifying to seek end of the file and retrieving 
the current file position out of that. Actually, it's somewhat 
surprising for me to see that System.FileSize is implemented using 
fpStat under Unix platforms rather than using fpLSeek (which should 
be the equivalent to the API calls used under other platforms if I 
understand it correctly). FileAge is a different story from this 
point of view.

Tomas




More information about the fpc-devel mailing list