Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4615394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:50:01+00:00 2026-05-22T01:50:01+00:00

Possible Duplicate: programatically get the file size from a remote file using delphi, before

  • 0

Possible Duplicate:
programatically get the file size from a remote file using delphi, before download it.

Say I have a local file:

C:\file.txt

And one on the web:

http://www.web.com/file.txt

How can I check whether the size are different, and if they’re different then //do something ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:50:02+00:00Added an answer on May 22, 2026 at 1:50 am

    To obtain the file size of a file on the Internet, do

    function WebFileSize(const UserAgent, URL: string): cardinal;
    var
      hInet, hURL: HINTERNET;
      len: cardinal;
      index: cardinal;
    begin
      result := cardinal(-1);
      hInet := InternetOpen(PChar(UserAgent),
        INTERNET_OPEN_TYPE_PRECONFIG,
        nil,
        nil,
        0);
      index := 0;
      if hInet <> nil then
        try
          hURL := InternetOpenUrl(hInet, PChar(URL), nil, 0, 0, 0);
          if hURL <> nil then
            try
              len := sizeof(result);
              if not HttpQueryInfo(hURL,
                HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER,
                @result,
                len,
                index) then
                RaiseLastOSError;
            finally
              InternetCloseHandle(hURL);
            end;
        finally
          InternetCloseHandle(hInet)
        end;
    end;
    

    For example, you can try

    ShowMessage(IntToStr(WebFileSize('Test Agent',
      'http://privat.rejbrand.se/test.txt')));
    

    To obtain the size of a local file, the simplest way is to FindFirstFile on it and read the TSearchRec. Slightly more elegant, though, is

    function GetFileSize(const FileName: string): cardinal;
    var
      f: HFILE;
    begin
      result := cardinal(-1);    
      f := CreateFile(PChar(FileName),
        GENERIC_READ,
        0,
        nil,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        0);
      if f <> 0 then
        try
          result := Windows.GetFileSize(f, nil);
        finally
          CloseHandle(f);
        end;
    end;
    

    Now you can do

    if GetFileSize('C:\Users\Andreas Rejbrand\Desktop\test.txt') =
               WebFileSize('UA', 'http://privat.rejbrand.se/test.txt') then
      ShowMessage('The two files have the same size.')
    else
      ShowMessage('The two files are not of the same size.')
    

    Notice: If in your case it is not enough to use 32 bits to represent the file sizes, you need to do some minor changes to the two functions above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to run a database script file from Delphi? I have a
Possible Duplicate: comparing contents of two files using python I have a file name
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicates: How can I get the size of an array from a pointer
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: How to compare two word documents? How can you get the diff
Possible Duplicate: How to programmatically get DLL dependencies On Windows, in a C++ program,
Possible Duplicate: How to programatically take a screenshot on Android? How to capture the
Possible Duplicate: Elevating process privilege programatically? I'd like to build a console application in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.