0

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!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.