Obtain file size?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Obtain file size?

Zaaphod

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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Obtain file size?

Free Pascal - General mailing list

Am 07.10.2017 01:13 schrieb "James Richters" <[hidden email]>:
>
> 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?

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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Obtain file size?

Paul Nance
In reply to this post by Zaaphod
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" <[hidden email]> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Obtain file size?

Free Pascal - General mailing list

Am 07.10.2017 21:08 schrieb "Paul Nance" <[hidden email]>:
>
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal