Get File Size Of Open File

Discussion in 'C++' started by Jixz, Sep 7, 2010.

  1. Jixz

    Jixz New Member

    Joined:
    Sep 7, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    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!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice