Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. trying to get the size of a file

trying to get the size of a file

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clayman87
    wrote on last edited by
    #1

    Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.

    T M J 3 Replies Last reply
    0
    • C clayman87

      Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      The first arguments should be: const char *path - the routine shouldn't be modifying the text. const CString &path - Same thing again but also avoids an extra copy constructor. const std::string &path - Same thing as with const CString &path. Tim Smith I'm going to patent thought. I have yet to see any prior art.

      1 Reply Last reply
      0
      • C clayman87

        Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.

        M Offline
        M Offline
        Michael P Butler
        wrote on last edited by
        #3

        Off the top of my head.

        // Open file for reading
        if ((hFile = CreateFile (filePath, GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE)NULL)) == (HANDLE)(-1))
        {
        return 0;
        }

        DWORD dwFileSize = GetFileSize (hFile, NULL); // Get the size of the file.

        return dwFileSize;

        Michael But you know when the truth is told, That you can get what you want or you can just get old, Your're going to kick off before you even get halfway through. When will you realise... Vienna waits for you? - "The Stranger," Billy Joel

        1 Reply Last reply
        0
        • C clayman87

          Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #4

          There are various ways, but you probably want one of the following: GetFileSize() GetFileSizeEx() (For sizes larger than a DWORD value) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

          C 1 Reply Last reply
          0
          • J Joe Woodbury

            There are various ways, but you probably want one of the following: GetFileSize() GetFileSizeEx() (For sizes larger than a DWORD value) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

            C Offline
            C Offline
            clayman87
            wrote on last edited by
            #5

            thank you both for the help, anyway I've managed to figure it out myself, however due to a netsplit I couldn't access codeproject.com, I made a func almost similar you described. btw. it's possible to get the size of a file with GetFileSize, as if it puts the high dword to the DWORD pointed by the second argument.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups