Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory size with DirectoryInfo

Status
Not open for further replies.

bigtimmin

MIS
Apr 12, 2005
125
US
How does one retrieve the directory size (in bytes) using DirectoryInfo, without looping through the directory and retrieving each file size with FileInfo? I'm currently using the FileSystemObject, example:
Code:
Dim oFS As Object = CreateObject("Scripting.FileSystemObject")
Dim oDir As Object = oFS.GetFolder("MyFolder") 
Dim nBytes as Long = CLng([b]oDir.Size[/b]) [COLOR=green]'total folder size[/color]

Maybe this world is another planet’s Hell.
Aldous Huxley

eyes_015.gif___1129027102664
eyes_015.gif___1129027102664
 
I don't know if you can - I've used a recursive function in the past but this obviously has to loop through all the files and sub-directories e.g.:
Code:
Public Shared Function Size(ByVal dirInfo As System.IO.DirectoryInfo) As Long
  Dim total As Long =  0 
 
  Dim file As System.IO.FileInfo
  For Each file In dirInfo.GetFiles()
    total += file.Length
  Next
 
  Dim dir As System.IO.DirectoryInfo
  For Each dir In dirInfo.GetDirectories()
    total += Size(dir)
  Next
 
  Return total
End Function


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top