Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 7th, 2002, 09:08 AM
Beans4You's Avatar
Beans4You Beans4You is offline
Some day I will be a Lambda!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: NJ
Posts: 18 Beans4You User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Retrieve a Folder -or- Directory Size

I have tried in vain to retrieve the size of a Windows NTFS folder through a VC++ Application.

If any one could please help a novice C++ programmer I would greatly appreciate it.

Thanks in advance...

Beans4You

Reply With Quote
  #2  
Old September 16th, 2002, 01:49 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,589 Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 1 m 37 sec
Reputation Power: 1001
I remember helping you traverse an NTFS directory a while earlier.
http://forums.devshed.com/showthrea...&threadid=39656

All you need to do is add some more code to sum up the file sizes. You can get the filesize of each file from the WIN32_FIND_DATA structure. For more info on the structure, see this:
http://msdn.microsoft.com/library/d...2_FIND_DATA.asp

So the filesize would be computed in your code as something like this:
(data.nFileSizeHigh * MAXDWORD) + data.nFileSizeLow


Add them up into a global variable and you should be set. BTW I think this post really belongs in the C/C++ forum rather than the algorithms forum.

Reply With Quote
  #3  
Old September 19th, 2002, 06:15 AM
Beans4You's Avatar
Beans4You Beans4You is offline
Some day I will be a Lambda!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: NJ
Posts: 18 Beans4You User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Scorpions4ever,

First, thanks for all your help - now and past -

Second, why use the (data.nFileSizeHigh * MAXDWORD)? I always get a zero as a value when calling data.nFileSizeHigh.

Third, I have done something similar but not using the (data.nFileSizeHigh * MAXDWORD). My problem is, is that the algorithm will not enter directories such as "System Volume Information" and therefore I get a total which is smaller than the value returned by Windows in the properties of the directory, and a strange phenomena also happens. I can run the function several times right after each other and get slightly different results each time.

What I was hoping to find is some attribute or system call which I could send the directory path and get the size. There has to be some way to do it, I mean how does Windows perform this task? Every time you request the properties of a directory does it go through the trouble to recursively search the directory?

Eric

Reply With Quote
  #4  
Old September 19th, 2002, 04:19 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,589 Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 1 m 37 sec
Reputation Power: 1001
>> First, thanks for all your help - now and past -

I'm always glad to help

>> Second, why use the (data.nFileSizeHigh * MAXDWORD)? I always get a zero as a value when calling data.nFileSizeHigh.

Because the documentation from Micro$oft says to do so. If you check out the link that I posted above (the one to MSDN), you'll see that it says:
"nFileSizeHigh
High-order DWORD value of the file size, in bytes. This value is zero unless the file size is greater than MAXDWORD. The size of the file is equal to (nFileSizeHigh * MAXDWORD) + nFileSizeLow."

Normally, nFileSizeHigh will be 0, unless your filesize exceeds MAXDWORD, which is 2^32-1 (around 4+GB). There are few files currently available that are this large, but in the future, this may become more common. Can anyone say "bloatware!"


>>Third, I have done something similar but not using the (data.nFileSizeHigh * MAXDWORD). My problem is, is that the algorithm will not enter directories such as "System Volume Information" and therefore I get a total which is smaller than the value returned by Windows in the properties of the directory, and a strange phenomena also happens. I can run the function several times right after each other and get slightly different results each time.

Without seeing your code, I can't really tell you what's wrong. BTW if you check the properties of the System Volume Information folder in Explorer, the size returned is 0 bytes, so I suspect this isn't affecting your total. Maybe the size of your total is being affected by cached files or cookies, if you're websurfing at the same time?


>>What I was hoping to find is some attribute or system call which I could send the directory path and get the size. There has to be some way to do it, I mean how does Windows perform this task? Every time you request the properties of a directory does it go through the trouble to recursively search the directory?

I'm not aware of any such call. I think Explorer also recursively searches to compute the size of the directory, because I can actually see it adding up the file sizes, when I check the properties of a large folder (such as Program Files). After it computes it for the first time, I think it caches the value so that the next time around, the computation is much faster. There is a fast way to get available space or used space for a drive though, instead of going through the directories. For this purpose, you can use GetDiskFreeSpace() or GetDiskFreeSpaceEx().

Hope this helps!

Last edited by Scorpions4ever : September 19th, 2002 at 04:46 PM.

Reply With Quote
  #5  
Old September 19th, 2002, 05:22 PM
Beans4You's Avatar
Beans4You Beans4You is offline
Some day I will be a Lambda!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: NJ
Posts: 18 Beans4You User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
A most in-depth answer.

Thank you much.


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Retrieve a Folder -or- Directory Size


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT