Answered by:
Getting directory size of all directories listed in a listbox.

Question
-
I have a listbox with a list of directories. I want to get the grand total diretory size of all the directory listed in the listbox. Can someone help.
Monday, August 20, 2007 4:12 AM
Answers
-
Start with the code from this post on this thread.Monday, August 20, 2007 4:33 AMModerator
-
What is the purpose of OldDS? Since you are calculating a running total you can just replace
Code SnippetTotalDS = NewDS + OldDS
OldDS = TotalDS
with
Code SnippetTotalDS = TotalDS + NewDSAnd unless you did not post all the code, what you have would not work since your items array would be empty. If your ListBox1.Items collection contains your directory paths, how are they getting into items array? You would probably be better off replacing
Code SnippetFor Each item As String in items
with
Code SnippetFor Each item as String in ListBox1.Items
(or something like this since I did not test it...)
- Jason
Monday, August 20, 2007 5:03 PM
All replies
-
Unfortunatelythere is no... GetDirectorySize() like function in .NET... instead you've got to make your own or use someone elses that countes the size of all of the files within and all sub dirs... take a look at the example on this thread. With it you'd just need to call it once on the parent of the dir's in your listbox and you should have your total.
Monday, August 20, 2007 4:19 AMModerator -
Monday, August 20, 2007 4:25 AM
-
Start with the code from this post on this thread.Monday, August 20, 2007 4:33 AMModerator
-
Monday, August 20, 2007 5:06 AM
-
Two ways... you can either call that function multiple times, once for each folder in your list box and add up the results (from those calls) yourself... or if all of those folders have the same parent folder... you could call that function on that parent folder and use the number it returns.
Monday, August 20, 2007 5:11 AMModerator -
Since they don't have the same parent folder. That means I'll have to run it multiple time.
Monday, August 20, 2007 5:14 AM -
This is what i have so far, but it doesn't work right
oldds = 0
For Each item As String In itemsnewds = DirectorySize(item,
True)TotalDS = NewDS + OldDS
OldDS = TotalDS
NextTextBox6.Text = TotalDS
Monday, August 20, 2007 5:22 AM -
can someone please help.Monday, August 20, 2007 4:45 PM
-
What is the purpose of OldDS? Since you are calculating a running total you can just replace
Code SnippetTotalDS = NewDS + OldDS
OldDS = TotalDS
with
Code SnippetTotalDS = TotalDS + NewDSAnd unless you did not post all the code, what you have would not work since your items array would be empty. If your ListBox1.Items collection contains your directory paths, how are they getting into items array? You would probably be better off replacing
Code SnippetFor Each item As String in items
with
Code SnippetFor Each item as String in ListBox1.Items
(or something like this since I did not test it...)
- Jason
Monday, August 20, 2007 5:03 PM -
Monday, August 20, 2007 5:17 PM
-
ok but I have a question which may not fit here but I hope you can point me the right way. I have a program that flags errors after errors of "GetDirectorySize: Permission Denied x:\ #70" if I run this program as domain admin it does not have this errors and x:\ is a mapped NFS drive. how can I get my Domain Users group to have this permission without making them all Domain Admin's?
thanks
Wednesday, March 12, 2008 9:58 PM -
Good luck in getting any help with Vista security. I've posted questions on several forums with no valid responses.
You wopuld think that the getfolder function in vbscript wopuld get the direcotry sizes that the above person was asking about. But it gets the #70 error even when run as the real administrator and no one seems to know why.
Thursday, March 13, 2008 3:35 AM