getting directory size in vb 
Author Message
 getting directory size in vb

Please get me started on an vb app that will search network home directories
and give me a list of top 5 directory names according to size.

will this app bog down network?

-Newbie



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
Use FileSystemObjects to recursively add up the size of all the files.

Jonathan Allen


Quote:
> Please get me started on an vb app that will search network home
directories
> and give me a list of top 5 directory names according to size.

> will this app bog down network?

> -Newbie



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
Thank you, I have tried this and it seems to work nice.

I made a dirlistbox for users to choose directory, is there a way to have
the cursor go to the root of the drive in this directory list??  it always
goes to a lower level directory.  I just want it to start at top level.

Thanks


Quote:
> Use FileSystemObjects to recursively add up the size of all the files.

> Jonathan Allen



> > Please get me started on an vb app that will search network home
> directories
> > and give me a list of top 5 directory names according to size.

> > will this app bog down network?

> > -Newbie



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
I don't know. I've never had to use it.

Jonathan Allen


Quote:
> Thank you, I have tried this and it seems to work nice.

> I made a dirlistbox for users to choose directory, is there a way to have
> the cursor go to the root of the drive in this directory list??  it always
> goes to a lower level directory.  I just want it to start at top level.

> Thanks



> > Use FileSystemObjects to recursively add up the size of all the files.

> > Jonathan Allen



> > > Please get me started on an vb app that will search network home
> > directories
> > > and give me a list of top 5 directory names according to size.

> > > will this app bog down network?

> > > -Newbie



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb


Quote:
> Thank you, I have tried this and it seems to work nice.

> I made a dirlistbox for users to choose directory, is there a way to
have
> the cursor go to the root of the drive in this directory list??  it
always
> goes to a lower level directory.  I just want it to start at top
level.

> Thanks

Set the Path property. Like so: Dir1.Path = "C:\"

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
Thank you!!

I have 2 more questions:

1. how do I put a cancel button on a form that will stop going thru each
directory and getting the size attribute.   I tried to check if button was
pressed in each iteration of loop but it did not work.

2.  I am using a progress bar also, and how can I change the cursor to be an
hour glass during processing thru a looop.

3.  BOnus question;  how can I right justify text in a string, I tried the
rset function and it did not work, i think it has to do with problem with
fixed lenght font, perhaps?

Thanks for help


Quote:


> > Thank you, I have tried this and it seems to work nice.

> > I made a dirlistbox for users to choose directory, is there a way to
> have
> > the cursor go to the root of the drive in this directory list??  it
> always
> > goes to a lower level directory.  I just want it to start at top
> level.

> > Thanks

> Set the Path property. Like so: Dir1.Path = "C:\"

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
Ed,

To answer your 2+1 question I created a simple example with 1 form, a
DirListBox, a CommandButton and a Label on it.
Paste the following code and try it.
==================================
Option Explicit

Dim mStopCounting As Boolean

Private Sub Command1_Click()
    mStopCounting = True  '<-- Question 1
End Sub

Private Sub Dir1_Change()
    CountFiles Dir1.Path
End Sub

Private Sub Dir1_Click()
    CountFiles Dir1.List(Dir1.ListIndex)
End Sub

Private Sub Form_Load()
    Command1.Caption = "Cancel"
    Label1.Alignment = vbRightJustify  '<-- Bonus-question ??
    Dir1.ListIndex = 0  'Start at the top-level
End Sub

Private Sub CountFiles(sMap As String)
Dim iFiles As Integer
Dim lSize As Long
Dim sFile As String
    Screen.MousePointer = vbArrowHourglass  '<-- Question 2
    mStopCounting = False
    Command1.Enabled = True
    If Right(sMap, 1) = "\" Then
        sMap = Left(sMap, Len(sMap) - 1)
    End If
    sFile = Dir(sMap & "\*.*")
    Do Until sFile = ""
        DoEvents
        If mStopCounting Then  '<-- Question 1
            Label1.Caption = sMap & vbNewLine & _
                "Counting interrupted."
            Exit Do
        End If
        iFiles = iFiles + 1
        lSize = lSize + FileLen(sMap & "\" & sFile)
        Label1.Caption = sMap & vbNewLine & _
                Format(iFiles, "#,##0") & " files" & vbNewLine & _
                Format(lSize / 1024, "#,##0") & " kb"
        sFile = Dir
    Loop
    Command1.Enabled = False
    Screen.MousePointer = vbDefault  '<-- Question 2
End Sub
==================================

Hope this helps,
Johan.



Quote:
> Thank you!!

> I have 2 more questions:

> 1. how do I put a cancel button on a form that will stop going thru each
> directory and getting the size attribute.   I tried to check if button was
> pressed in each iteration of loop but it did not work.

> 2.  I am using a progress bar also, and how can I change the cursor to be
an
> hour glass during processing thru a looop.

> 3.  BOnus question;  how can I right justify text in a string, I tried the
> rset function and it did not work, i think it has to do with problem with
> fixed lenght font, perhaps?

> Thanks for help





> > > Thank you, I have tried this and it seems to work nice.

> > > I made a dirlistbox for users to choose directory, is there a way to
> > have
> > > the cursor go to the root of the drive in this directory list??  it
> > always
> > > goes to a lower level directory.  I just want it to start at top
> > level.

> > > Thanks

> > Set the Path property. Like so: Dir1.Path = "C:\"

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
In case your wondering, the reason Johan's code works is the DoEvents
keyword. That tells your program to pause for a sec and look at what the
user is doing.

Jonathan Allen


Quote:
> Ed,

> To answer your 2+1 question I created a simple example with 1 form, a
> DirListBox, a CommandButton and a Label on it.
> Paste the following code and try it.
> ==================================
> Option Explicit

> Dim mStopCounting As Boolean

> Private Sub Command1_Click()
>     mStopCounting = True  '<-- Question 1
> End Sub

> Private Sub Dir1_Change()
>     CountFiles Dir1.Path
> End Sub

> Private Sub Dir1_Click()
>     CountFiles Dir1.List(Dir1.ListIndex)
> End Sub

> Private Sub Form_Load()
>     Command1.Caption = "Cancel"
>     Label1.Alignment = vbRightJustify  '<-- Bonus-question ??
>     Dir1.ListIndex = 0  'Start at the top-level
> End Sub

> Private Sub CountFiles(sMap As String)
> Dim iFiles As Integer
> Dim lSize As Long
> Dim sFile As String
>     Screen.MousePointer = vbArrowHourglass  '<-- Question 2
>     mStopCounting = False
>     Command1.Enabled = True
>     If Right(sMap, 1) = "\" Then
>         sMap = Left(sMap, Len(sMap) - 1)
>     End If
>     sFile = Dir(sMap & "\*.*")
>     Do Until sFile = ""
>         DoEvents
>         If mStopCounting Then  '<-- Question 1
>             Label1.Caption = sMap & vbNewLine & _
>                 "Counting interrupted."
>             Exit Do
>         End If
>         iFiles = iFiles + 1
>         lSize = lSize + FileLen(sMap & "\" & sFile)
>         Label1.Caption = sMap & vbNewLine & _
>                 Format(iFiles, "#,##0") & " files" & vbNewLine & _
>                 Format(lSize / 1024, "#,##0") & " kb"
>         sFile = Dir
>     Loop
>     Command1.Enabled = False
>     Screen.MousePointer = vbDefault  '<-- Question 2
> End Sub
> ==================================

> Hope this helps,
> Johan.



> > Thank you!!

> > I have 2 more questions:

> > 1. how do I put a cancel button on a form that will stop going thru each
> > directory and getting the size attribute.   I tried to check if button
was
> > pressed in each iteration of loop but it did not work.

> > 2.  I am using a progress bar also, and how can I change the cursor to
be
> an
> > hour glass during processing thru a looop.

> > 3.  BOnus question;  how can I right justify text in a string, I tried
the
> > rset function and it did not work, i think it has to do with problem
with
> > fixed lenght font, perhaps?

> > Thanks for help





> > > > Thank you, I have tried this and it seems to work nice.

> > > > I made a dirlistbox for users to choose directory, is there a way to
> > > have
> > > > the cursor go to the root of the drive in this directory list??  it
> > > always
> > > > goes to a lower level directory.  I just want it to start at top
> > > level.

> > > > Thanks

> > > Set the Path property. Like so: Dir1.Path = "C:\"

> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
Jonathan Allen,

If you mean by "pause for a sec" that the program "waits for 1/60 minute",
it's not true. It yields execution so that the operating system can process
other events.
The help file says:
DoEvents passes control to the operating system. Control is returned after
the operating system has finished processing the events in its queue.

Johan.



Quote:
> In case your wondering, the reason Johan's code works is the DoEvents
> keyword. That tells your program to pause for a sec and look at what the
> user is doing.

> Jonathan Allen



> > Ed,

> > To answer your 2+1 question I created a simple example with 1 form, a
> > DirListBox, a CommandButton and a Label on it.
> > Paste the following code and try it.
> > ==================================
> > Option Explicit

> > Dim mStopCounting As Boolean

> > Private Sub Command1_Click()
> >     mStopCounting = True  '<-- Question 1
> > End Sub

> > Private Sub Dir1_Change()
> >     CountFiles Dir1.Path
> > End Sub

> > Private Sub Dir1_Click()
> >     CountFiles Dir1.List(Dir1.ListIndex)
> > End Sub

> > Private Sub Form_Load()
> >     Command1.Caption = "Cancel"
> >     Label1.Alignment = vbRightJustify  '<-- Bonus-question ??
> >     Dir1.ListIndex = 0  'Start at the top-level
> > End Sub

> > Private Sub CountFiles(sMap As String)
> > Dim iFiles As Integer
> > Dim lSize As Long
> > Dim sFile As String
> >     Screen.MousePointer = vbArrowHourglass  '<-- Question 2
> >     mStopCounting = False
> >     Command1.Enabled = True
> >     If Right(sMap, 1) = "\" Then
> >         sMap = Left(sMap, Len(sMap) - 1)
> >     End If
> >     sFile = Dir(sMap & "\*.*")
> >     Do Until sFile = ""
> >         DoEvents
> >         If mStopCounting Then  '<-- Question 1
> >             Label1.Caption = sMap & vbNewLine & _
> >                 "Counting interrupted."
> >             Exit Do
> >         End If
> >         iFiles = iFiles + 1
> >         lSize = lSize + FileLen(sMap & "\" & sFile)
> >         Label1.Caption = sMap & vbNewLine & _
> >                 Format(iFiles, "#,##0") & " files" & vbNewLine & _
> >                 Format(lSize / 1024, "#,##0") & " kb"
> >         sFile = Dir
> >     Loop
> >     Command1.Enabled = False
> >     Screen.MousePointer = vbDefault  '<-- Question 2
> > End Sub
> > ==================================

> > Hope this helps,
> > Johan.



> > > Thank you!!

> > > I have 2 more questions:

> > > 1. how do I put a cancel button on a form that will stop going thru
each
> > > directory and getting the size attribute.   I tried to check if button
> was
> > > pressed in each iteration of loop but it did not work.

> > > 2.  I am using a progress bar also, and how can I change the cursor to
> be
> > an
> > > hour glass during processing thru a looop.

> > > 3.  BOnus question;  how can I right justify text in a string, I tried
> the
> > > rset function and it did not work, i think it has to do with problem
> with
> > > fixed lenght font, perhaps?

> > > Thanks for help





> > > > > Thank you, I have tried this and it seems to work nice.

> > > > > I made a dirlistbox for users to choose directory, is there a way
to
> > > > have
> > > > > the cursor go to the root of the drive in this directory list??
it
> > > > always
> > > > > goes to a lower level directory.  I just want it to start at top
> > > > level.

> > > > > Thanks

> > > > Set the Path property. Like so: Dir1.Path = "C:\"

> > > > Sent via Deja.com http://www.deja.com/
> > > > Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb
Hi Johan,

Thanks so much for your help, I appreciate it.  I look forward to trying
this out.

For this bit of code:

        Label1.Caption = sMap & vbNewLine & _
                Format(iFiles, "#,##0") & " files" & vbNewLine & _
                Format(lSize / 1024, "#,##0") & " kb"
        sFile = Dir

I see you are forcing newlines and was wondeirng how I can apply this in
properties window for a label.  I have text that does not change but I would
like to enter an newline when I type it directrly in the properties window
for caption without haveing to do it in code.  THis text will never change,
is there a way to do this?

Also, I know how to center the label by right or left justifying it, but I
am storing the results in a string as you do above, then it will go in list
box,  will the above left justify the path, and right justify the numbe
within the string?  if so ingore this.  I will see later when I try your
code.

Another annoying thing I noticed:
When an application runs that will take some time to process, the window
cannot be moved or minimized like in other vb apps while running. Is there a
way to allow users to move or minimize and do something else while it is
running?

Thanks for all your help.  I hope I am not toooo much.

Ed

Quote:
> Ed,

> To answer your 2+1 question I created a simple example with 1 form, a
> DirListBox, a CommandButton and a Label on it.
> Paste the following code and try it.
> ==================================
> Option Explicit

> Dim mStopCounting As Boolean

> Private Sub Command1_Click()
>     mStopCounting = True  '<-- Question 1
> End Sub

> Private Sub Dir1_Change()
>     CountFiles Dir1.Path
> End Sub

> Private Sub Dir1_Click()
>     CountFiles Dir1.List(Dir1.ListIndex)
> End Sub

> Private Sub Form_Load()
>     Command1.Caption = "Cancel"
>     Label1.Alignment = vbRightJustify  '<-- Bonus-question ??
>     Dir1.ListIndex = 0  'Start at the top-level
> End Sub

> Private Sub CountFiles(sMap As String)
> Dim iFiles As Integer
> Dim lSize As Long
> Dim sFile As String
>     Screen.MousePointer = vbArrowHourglass  '<-- Question 2
>     mStopCounting = False
>     Command1.Enabled = True
>     If Right(sMap, 1) = "\" Then
>         sMap = Left(sMap, Len(sMap) - 1)
>     End If
>     sFile = Dir(sMap & "\*.*")
>     Do Until sFile = ""
>         DoEvents
>         If mStopCounting Then  '<-- Question 1
>             Label1.Caption = sMap & vbNewLine & _
>                 "Counting interrupted."
>             Exit Do
>         End If
>         iFiles = iFiles + 1
>         lSize = lSize + FileLen(sMap & "\" & sFile)
>         Label1.Caption = sMap & vbNewLine & _
>                 Format(iFiles, "#,##0") & " files" & vbNewLine & _
>                 Format(lSize / 1024, "#,##0") & " kb"
>         sFile = Dir
>     Loop
>     Command1.Enabled = False
>     Screen.MousePointer = vbDefault  '<-- Question 2
> End Sub
> ==================================

> Hope this helps,
> Johan.



> > Thank you!!

> > I have 2 more questions:

> > 1. how do I put a cancel button on a form that will stop going thru each
> > directory and getting the size attribute.   I tried to check if button
was
> > pressed in each iteration of loop but it did not work.

> > 2.  I am using a progress bar also, and how can I change the cursor to
be
> an
> > hour glass during processing thru a looop.

> > 3.  BOnus question;  how can I right justify text in a string, I tried
the
> > rset function and it did not work, i think it has to do with problem
with
> > fixed lenght font, perhaps?

> > Thanks for help





> > > > Thank you, I have tried this and it seems to work nice.

> > > > I made a dirlistbox for users to choose directory, is there a way to
> > > have
> > > > the cursor go to the root of the drive in this directory list??  it
> > > always
> > > > goes to a lower level directory.  I just want it to start at top
> > > level.

> > > > Thanks

> > > Set the Path property. Like so: Dir1.Path = "C:\"

> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 getting directory size in vb


Quote:
> Hi Johan,

> Thanks so much for your help, I appreciate it.  I look forward to trying
> this out.

> For this bit of code:

>         Label1.Caption = sMap & vbNewLine & _
>                 Format(iFiles, "#,##0") & " files" & vbNewLine & _
>                 Format(lSize / 1024, "#,##0") & " kb"
>         sFile = Dir

> I see you are forcing newlines and was wondeirng how I can apply this in
> properties window for a label.  I have text that does not change but I
would
> like to enter an newline when I type it directrly in the properties window
> for caption without haveing to do it in code.  THis text will never
change,
> is there a way to do this?

I don't think that a newline can be enterd in the propreties window; which
key should be pressed?
The best way is to fill the caption in the Form_Load event.

Quote:

> Also, I know how to center the label by right or left justifying it, but I
> am storing the results in a string as you do above, then it will go in
list
> box,  will the above left justify the path, and right justify the numbe
> within the string?  if so ingore this.  I will see later when I try your
> code.

Considder using the ListView. It's part of the "Microsoft Windows Common
Controls".

Quote:

> Another annoying thing I noticed:
> When an application runs that will take some time to process, the window
> cannot be moved or minimized like in other vb apps while running. Is there
a
> way to allow users to move or minimize and do something else while it is
> running?

Look at 'DoEvents'.
DoEvents passes control to the operating system and other applications can
'use the CPU'.

- Show quoted text -

Quote:

> Thanks for all your help.  I hope I am not toooo much.

> Ed


> > Ed,

> > To answer your 2+1 question I created a simple example with 1 form, a
> > DirListBox, a CommandButton and a Label on it.
> > Paste the following code and try it.
> > ==================================
> > Option Explicit

> > Dim mStopCounting As Boolean

> > Private Sub Command1_Click()
> >     mStopCounting = True  '<-- Question 1
> > End Sub

> > Private Sub Dir1_Change()
> >     CountFiles Dir1.Path
> > End Sub

> > Private Sub Dir1_Click()
> >     CountFiles Dir1.List(Dir1.ListIndex)
> > End Sub

> > Private Sub Form_Load()
> >     Command1.Caption = "Cancel"
> >     Label1.Alignment = vbRightJustify  '<-- Bonus-question ??
> >     Dir1.ListIndex = 0  'Start at the top-level
> > End Sub

> > Private Sub CountFiles(sMap As String)
> > Dim iFiles As Integer
> > Dim lSize As Long
> > Dim sFile As String
> >     Screen.MousePointer = vbArrowHourglass  '<-- Question 2
> >     mStopCounting = False
> >     Command1.Enabled = True
> >     If Right(sMap, 1) = "\" Then
> >         sMap = Left(sMap, Len(sMap) - 1)
> >     End If
> >     sFile = Dir(sMap & "\*.*")
> >     Do Until sFile = ""
> >         DoEvents
> >         If mStopCounting Then  '<-- Question 1
> >             Label1.Caption = sMap & vbNewLine & _
> >                 "Counting interrupted."
> >             Exit Do
> >         End If
> >         iFiles = iFiles + 1
> >         lSize = lSize + FileLen(sMap & "\" & sFile)
> >         Label1.Caption = sMap & vbNewLine & _
> >                 Format(iFiles, "#,##0") & " files" & vbNewLine & _
> >                 Format(lSize / 1024, "#,##0") & " kb"
> >         sFile = Dir
> >     Loop
> >     Command1.Enabled = False
> >     Screen.MousePointer = vbDefault  '<-- Question 2
> > End Sub
> > ==================================

> > Hope this helps,
> > Johan.



> > > Thank you!!

> > > I have 2 more questions:

> > > 1. how do I put a cancel button on a form that will stop going thru
each
> > > directory and getting the size attribute.   I tried to check if button
> was
> > > pressed in each iteration of loop but it did not work.

> > > 2.  I am using a progress bar also, and how can I change the cursor to
> be
> > an
> > > hour glass during processing thru a looop.

> > > 3.  BOnus question;  how can I right justify text in a string, I tried
> the
> > > rset function and it did not work, i think it has to do with problem
> with
> > > fixed lenght font, perhaps?

> > > Thanks for help





> > > > > Thank you, I have tried this and it seems to work nice.

> > > > > I made a dirlistbox for users to choose directory, is there a way
to
> > > > have
> > > > > the cursor go to the root of the drive in this directory list??
it
> > > > always
> > > > > goes to a lower level directory.  I just want it to start at top
> > > > level.

> > > > > Thanks

> > > > Set the Path property. Like so: Dir1.Path = "C:\"

> > > > Sent via Deja.com http://www.deja.com/
> > > > Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Getting Directory size in VB???

2. getting directory size

3. Getting the size of files directories, and drives....

4. Getting directory size - how ?

5. Getting size of entire directory

6. Getting a detailed directory listing using Internet transfer control, file sizes

7. Getting the total size of a directory

8. getting the size of a directory

9. API for getting the size of a directory

10. Getting specified directory (with subdirs) size

11. Getting the total size of a directory

12. Size file or size directory

 

 
Powered by phpBB® Forum Software