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