locked
Getting directory size of all directories listed in a listbox. RRS feed

  • 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 AM
    Moderator
  • What is the purpose of OldDS? Since you are calculating a running total you can just replace

     

    Code Snippet

    TotalDS = NewDS + OldDS

    OldDS = TotalDS

     

     

    with

     

    Code Snippet
    TotalDS = TotalDS + NewDS

     

     

    And 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 Snippet

    For Each item As String in items

     

     

    with

     

    Code Snippet

    For 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 AM
    Moderator
  •  

    I'm fairly new to VB. Is there any way you can point me in the right direction in getting the total directory size.
    Monday, August 20, 2007 4:25 AM
  • Start with the code from this post on this thread.
    Monday, August 20, 2007 4:33 AM
    Moderator
  •  

    I understand how to get one directory. I'm not sure how to get it to read the directories out of the listbox and get a grand total.
    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 AM
    Moderator
  • 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

     

    Dim TotalDS As Long

    Dim OldDS As Long

    Dim NewDS As Long

    Dim items(Me.ListBox1.Items.Count - 1) As Object

    oldds = 0

    For Each item As String In items

    newds = DirectorySize(item, True)

    TotalDS = NewDS + OldDS

    OldDS = TotalDS

    Next

    TextBox6.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 Snippet

    TotalDS = NewDS + OldDS

    OldDS = TotalDS

     

     

    with

     

    Code Snippet
    TotalDS = TotalDS + NewDS

     

     

    And 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 Snippet

    For Each item As String in items

     

     

    with

     

    Code Snippet

    For 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
  •  

    Thanks for pointing me in the right direction.
    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