G
grouped2000
g'day group,
I need some code that will give me the total size of a folder. In the
MSDN I've found some code, but I cannot figure out how to use this code
at all ...
I am quite new to .NET, I have been using VB6 always. Can anyone point
me in the right direction?
How will the following code give me the total size of al files in
folder "c:\test" ? Where do I put this code? And how do I get the total
size out of this class and function?
thanks,
Ed
--------------------
Imports System
Imports System.IO
Imports Microsoft.VisualBasic
' the above is already at the right spot in the code
Public Class ShowDirSize
Public Shared Function DirSize(ByVal d As DirectoryInfo) As
Long
Dim Size As Long = 0
' Add file sizes.
Dim fis As FileInfo() = d.GetFiles()
Dim fi As FileInfo
For Each fi In fis
Size += fi.Length
Next fi
' Add subdirectory sizes.
Dim subs() As Boolean
'If subs(counter) = True Then
Dim dis As DirectoryInfo() = d.GetDirectories()
Dim di As DirectoryInfo
For Each di In dis
Size += DirSize(di)
Next di
Return Size
'End If
End Function 'DirSize
Public Overloads Shared Sub Main(ByVal args() As String)
If args.Length <> 1 Then
Console.WriteLine("You must provide a directory
argument at the command line.")
Else
Dim d As New DirectoryInfo(args(0))
Console.WriteLine("The size of {0} and its
subdirectories is {1} bytes.", d, DirSize(d))
End If
End Sub 'Main
End Class 'ShowDirSize
I need some code that will give me the total size of a folder. In the
MSDN I've found some code, but I cannot figure out how to use this code
at all ...
I am quite new to .NET, I have been using VB6 always. Can anyone point
me in the right direction?
How will the following code give me the total size of al files in
folder "c:\test" ? Where do I put this code? And how do I get the total
size out of this class and function?
thanks,
Ed
--------------------
Imports System
Imports System.IO
Imports Microsoft.VisualBasic
' the above is already at the right spot in the code
Public Class ShowDirSize
Public Shared Function DirSize(ByVal d As DirectoryInfo) As
Long
Dim Size As Long = 0
' Add file sizes.
Dim fis As FileInfo() = d.GetFiles()
Dim fi As FileInfo
For Each fi In fis
Size += fi.Length
Next fi
' Add subdirectory sizes.
Dim subs() As Boolean
'If subs(counter) = True Then
Dim dis As DirectoryInfo() = d.GetDirectories()
Dim di As DirectoryInfo
For Each di In dis
Size += DirSize(di)
Next di
Return Size
'End If
End Function 'DirSize
Public Overloads Shared Sub Main(ByVal args() As String)
If args.Length <> 1 Then
Console.WriteLine("You must provide a directory
argument at the command line.")
Else
Dim d As New DirectoryInfo(args(0))
Console.WriteLine("The size of {0} and its
subdirectories is {1} bytes.", d, DirSize(d))
End If
End Sub 'Main
End Class 'ShowDirSize