2021. 6. 11. 05:36ㆍ카테고리 없음
How to Get File Size in Bytes using Delphi / Object Pascal? November 5, 2014 2 Comments code, delphi, I/O File, object pascal, programming languages, Win32 API If you want to get the file size in bytes for a file, you can use the following function in Delphi/Object Pascal. For starters, the biggest (one of anyways) size offender in Delphi is the forms unit, which accounts for appx 200K (varies by Delphi version). SysUtils and Classes adds another appx 60K, the Controls unit, your code, the base 16K required by the System unit, etc. You get the picture I'm sure. It all adds up.
I got the source below from a third-party site explaining how to download a file from the internet using WinInet
. I'm not too familiar with API, and I took at look at the WinInet
unit but did not see any API calls like what I need.
What I'm doing is adding the ability to report back progress of downloading a file. This procedure I've already wrapped inside of a TThread
and everything works fine. However, just one missing piece: Finding the total size of the source file before downloading.
See below where I have a comment //HOW TO GET TOTAL SIZE?
This is where I need to find out what is the total size of the file BEFORE I begin downloading it. How do I go about doing this? Because this code seems to not know the size of the file until it's done being downloaded - and that makes this addition irrelevant.
Shell Script Check File Size
3 Answers
You can use the HEAD method and check the Content-Length
to retrieve the file size of a remote file
Check these two Methods
WinInet
If you want execute a HEAD method you must use the HttpOpenRequest, HttpSendRequest and HttpQueryInfo WinInet functions .
Indy
Also check this code using indy.
RRUZRRUZAnswering the question of how to get a download size with WinInet. This is out of one of my file downloaders that is based on WinInet.
This is the method I use to get the download size:
Use of this method requires an open request handle, and does NOT require reading any of the data:
Unix Check File Size
HTH
Glenn1234Glenn1234after fixing the types it looks better like this:
to call it: