Get file size

I'm sending binary files from a server to clients using sockets (much like simple ftp srv). I'd like the clients to show progressbar of the current download.

Because of this, I'd like the server to send file details (size most importantly) to the client before sending the binary. How do I get the details and send? I know about filesize(..), but it seams strange having to open and close the file before sending, just to have it opened again by the steam?

Instead of using FileExists, use FindFirst() instead... This function not only tells you if the file exists, you also get a nice TSearchRec record on succes full useful information. Something like this:

var
FromFile: file of byte;
Source: String; // string that have the true path to file
FileLength: longint;
begin
if FileExists (strFile) then
begin
AssignFile(FromFile, Source);
reset(FromFile);
FileLength := FileSize(FromFile); // now FileLength have the size of the file
CloseFile(FromF);
// Here you already know the FileLength, So, You can send the Length to client
...