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. Folder/File Size?!?

Folder/File Size?!?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structurestutorialquestion
4 Posts 3 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.
  • G Offline
    G Offline
    Greven
    wrote on last edited by
    #1

    I have been racking my brain for a while now trying to make my program track down the size of a folder/file. I would like to track how much space a folder is using on the hard drive, which I have determined that means recursing through the sub folders and adding up the size of all files... Ugh! Is there an easier way? If not, the problem I'm running into at this point is simply finding the size of the file! I've looked into every which way of find the file sizes and they all want some variable/handle that I don't have... I've been looking through the code for the tree's here and have found some very nice tips and stuff, but of course (as always) they are in dialog boxes with special controls, yadda yadda yadda. (Doesn't anyone else use MFC with a doc/view?) But I'm not seeing how to add up the size of files and stuff. Please, someone help me out. I'm getting frustrated to the point that I can't even explain it right X| Programming in binary is as easy as 01 10 11.

    R 1 Reply Last reply
    0
    • G Greven

      I have been racking my brain for a while now trying to make my program track down the size of a folder/file. I would like to track how much space a folder is using on the hard drive, which I have determined that means recursing through the sub folders and adding up the size of all files... Ugh! Is there an easier way? If not, the problem I'm running into at this point is simply finding the size of the file! I've looked into every which way of find the file sizes and they all want some variable/handle that I don't have... I've been looking through the code for the tree's here and have found some very nice tips and stuff, but of course (as always) they are in dialog boxes with special controls, yadda yadda yadda. (Doesn't anyone else use MFC with a doc/view?) But I'm not seeing how to add up the size of files and stuff. Please, someone help me out. I'm getting frustrated to the point that I can't even explain it right X| Programming in binary is as easy as 01 10 11.

      R Offline
      R Offline
      Richard Ellis
      wrote on last edited by
      #2

      G'Day Greven, Maybe I have mis-understood what you are trying to do but you can use CFindFile to recurse sub directories. CFindFile has a member function GetLength() which returns the size of a found file. So it is easy to step through a directory and work out its size something like will come close (cut and pasted from existing code so I may have chopped some bits out but you should get the drift) TraverseDirectory(CString strDirectory) { int nBytes = 0; BOOL bWorking = finder.FindFile(strDirectory); while (bWorking) { bWorking = finder.FindNextFile(); strFileName = finder.GetFilePath(); if (finder.IsDirectory()) { if (!finder.IsDots()) TraverseDirectory(strFileName); } else { nBytes = finder.GetLength(); } } You can also use GetDiskFreeSpaceEx to determine free space information. Hope that helps. Richard.

      G 1 Reply Last reply
      0
      • R Richard Ellis

        G'Day Greven, Maybe I have mis-understood what you are trying to do but you can use CFindFile to recurse sub directories. CFindFile has a member function GetLength() which returns the size of a found file. So it is easy to step through a directory and work out its size something like will come close (cut and pasted from existing code so I may have chopped some bits out but you should get the drift) TraverseDirectory(CString strDirectory) { int nBytes = 0; BOOL bWorking = finder.FindFile(strDirectory); while (bWorking) { bWorking = finder.FindNextFile(); strFileName = finder.GetFilePath(); if (finder.IsDirectory()) { if (!finder.IsDots()) TraverseDirectory(strFileName); } else { nBytes = finder.GetLength(); } } You can also use GetDiskFreeSpaceEx to determine free space information. Hope that helps. Richard.

        G Offline
        G Offline
        Greven
        wrote on last edited by
        #3

        That is exactly what I have been looking for... Thank you very much. And you know the worst part? I've used CFindFile many times before... Just never noticed the GetLength() function... (maybe it's just a really bad name for it ;P Programming in binary is as easy as 01 10 11.

        R 1 Reply Last reply
        0
        • G Greven

          That is exactly what I have been looking for... Thank you very much. And you know the worst part? I've used CFindFile many times before... Just never noticed the GetLength() function... (maybe it's just a really bad name for it ;P Programming in binary is as easy as 01 10 11.

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          You can also use CFile::GetStatus() to get the size of any file. /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com

          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