To make a long story short here is the situation I'm in right now:

I have one thread downloading a file from the web to a local file.
I need the other thread to get the local file's current size AS its downloading.

So, what would you guys recommend to do this? Here's what I've gone through already:

long begin,end,size;
  ifstream myfile ("C:\\HOCR\\MalwareBytesSetup.exe",);
  begin = myfile.tellg();
  myfile.seekg (0, ios::end);
  end = myfile.tellg();
  myfile.close();
  size = end-begin;

This won't work becuase the file is open by the 'downloading' thread.

struct stat fileStat; 
    stat( "C:\\HOCR\\MalwareBytesSetup.exe", &fileStat ); 
    int filesize=fileStat.st_size;

This WILL get the current size, but it isn't updated as the file downloads. Although, it does update if you refresh the c:\HOCR folder in explorer. (Maybe that can be done programmatically?)

Thanks for your help in advanced!

why don't you just have the threads that's downloading the file tell the other thread how much of the file it has downloaded? If you are using sockets the thread that is doing the downloading must know how many bytes it has downloaded, unless of course you are using some library that hids that information from it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.