Menu

Retriving file progress

2002-10-16
2012-09-26
  • Nobody/Anonymous

    Dear Forum,  I am trying to write a windows application that copies files from a CD.  How do I get the file progress of the installation? I'm using the CopyFile() function and I want a progress control to show progress.  How do I get the file progress of the installation?  I don't need a lot of code, but a few lines would be nice.  Thanks!

     
    • Nobody/Anonymous

      Hmm, one way I can think of doing this that may be actually faster than CopyFile() would be to use malloc() to build like a one meg chunk or something in memory, then fopen() the file, then fread() sequentlially. Each time you incremement progress bar. You can obtain a file's size by using my getFileSize() function. Observe...

      // Returns the file size of pszFileName in bytes. -1 on error...
      int getFileSize(char *pszFileName)
      {
          // Variables...
          long lFileSize = 0;
          FILE *someFile;

          // Open the file...
          someFile = fopen(pszFileName, "r");

          // Check for error...
          if(!someFile)
              return -1;

          // Get file size...
          fseek(someFile, 0, SEEK_END);
          lFileSize = ftell(someFile);

          // Close stream...
          fclose(someFile);

          // Return file size...
          return lFileSize;
      }

      Good luck =)

      Kip

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.