Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-10

Obtain file size?

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Richters

I am wondering how to get the file size reported by the OS for a particular file without opening it. I tried to search for ‘Free Pascal File Size’ and variations but all I get are things like this:

https://www.freepascal.org/docs-html/rtl/system/filesize.html

which is not what I’m looking for.

I’ve been looking through the sysutils reference here:

https://www.freepascal.org/docs-html/rtl/sysutils/index-5.html

and I see disk size, but not file size…

Could someone please point me in the right direction?

James

Sven Barth
to James Richters

Am 07.10.2017 01:13 schrieb "James Richters" <

: I am wondering how to get the file size reported by the OS for a

particular file without opening it. I tried to search for ‘Free Pascal File Size’ and variations but all I get are things like this:

Show quoted text 22 lines
https://www.freepascal.org/docs-html/rtl/system/filesize.html which is not what I’m looking for. I’ve been looking through the sysutils reference here: https://www.freepascal.org/docs-html/rtl/sysutils/index-5.html and I see disk size, but not file size… Could someone please point me in the right direction?

TSearchRec contains a Size field so you can use FindFirst with the specific filename instead of a pattern (don't forget FindClose then ;) ) to have a cross platform solution.
Otherwise you'd need to use system specific mechanisms (e.g. GetFileAttributeEx on Windows, stat on *nix).

Regards,
Sven

Paul Nance

I've always (since Turbo Pascal and now with Free Pascal) used FILESIZE. It works like a charm.
Even if you do it in assembly its done the same as its done in pascal.

On Oct 6, 2017 7:14 PM, "James Richters"
wrote:

I am wondering how to get the file size reported by the OS for a particular file without opening it. I tried to search for ‘Free Pascal File Size’ and variations but all I get are things like this:

https://www.freepascal.org/docs-html/rtl/system/filesize.html

which is not what I’m looking for.

I’ve been looking through the sysutils reference here:

https://www.freepascal.org/docs-html/rtl/sysutils/index-5.html

and I see disk size, but not file size…

Could someone please point me in the right direction?

James

Sven Barth
to Paul Nance
"Paul Nance" wrote
I've always (since Turbo Pascal and now with Free Pascal) used FILESIZE.

It works like a charm.

Even if you do it in assembly its done the same as its done in pascal.

FileSize() has the disadvantage that you need to open the file. But what if you don't have permissions for that? Permissions to retrieve the file size when the file is closed are usually available on the other hand, but for this another mechanism must be used.

Regards,
Sven