Feedback

Ordergröße rekursiv bestimmen

Sprache: VB

Ordergröße bestimmen mit allen Dateien in allen Unterverzeichnisen
'Imports System.IO

Function GetFolderSize(ByVal DirPath As String, _
   Optional IncludeSubFolders as Boolean = True) As Long

  Dim lngDirSize As Long
  Dim objFileInfo As FileInfo
  Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath)
  Dim objSubFolder As DirectoryInfo

Try
 
  For Each objFileInfo In objDir.GetFiles()
    lngDirSize += objFileInfo.Length
  Next

If IncludeSubFolders then
  For Each objSubFolder In objDir.GetDirectories()
    lngDirSize += GetFolderSize(objSubFolder.FullName)
  Next
End if

Catch Ex As Exception
 

End Try

   Return lngDirSize
End Function
'Imports System.IO

Function GetFolderSize(ByVal DirPath As String, _
   Optional IncludeSubFolders as Boolean = True) As Long

  Dim lngDirSize As Long
  Dim objFileInfo As FileInfo
  Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath)
  Dim objSubFolder As DirectoryInfo

Try
 
  For Each objFileInfo In objDir.GetFiles()
    lngDirSize += objFileInfo.Length
  Next

If IncludeSubFolders then
  For Each objSubFolder In objDir.GetDirectories()
    lngDirSize += GetFolderSize(objSubFolder.FullName)
  Next
End if

Catch Ex As Exception
 

End Try

   Return lngDirSize
End Function

2 Kommentare