Delphi Check File Size

2021. 6. 11. 05:36카테고리 없음



  1. Shell Script Check File Size
  2. Unix Check File Size
  3. Check File Size Linux
Active4 years, 11 months ago

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.

Jerry DodgeJerry Dodge
15.9k22 gold badges116 silver badges273 bronze badges

Shell Script Check File Size

File

3 Answers

File

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.

RRUZRRUZ
125k13 gold badges314 silver badges446 bronze badges

Answering 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

Glenn1234SizeGlenn1234
2,0121 gold badge9 silver badges17 bronze badges

after fixing the types it looks better like this:

to call it:

Mario GreenMario Green

Check File Size Linux

Not the answer you're looking for? Browse other questions tagged delphidownloaddelphi-xe2wininetprogressive-download or ask your own question.