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
Alte URL:
/snippet/ordergroesse-rekursiv-bestimmen/564
Es heißt Ordner nich Order und diese Funktion gibts schon
Ich habe den Fehler korrigiert. Stimmt einen ähnlichen Snippet gibt es schon.