Get the size of a directory in bytes
Posted: Fri Jul 25, 2003 9:26 pm
Code updated for 5.20+
Just so its not lost in another post i'll echo it here
Just so its not lost in another post i'll echo it here

Code: Select all
;Return the size of a directory in bytes
Procedure.q DirectorySize(DirectoryID, DirectoryName.s)
If ExamineDirectory(DirectoryID, DirectoryName, "*.*")
While NextDirectoryEntry(DirectoryID)
Name.s = DirectoryEntryName(DirectoryID)
If DirectoryEntryType(DirectoryID) = #PB_DirectoryEntry_File
TotalFileSize.q + DirectoryEntrySize(DirectoryID)
ElseIf DirectoryEntryType(DirectoryID) = #PB_DirectoryEntry_Directory
If Name <> "." And Name <> ".."
TotalFileSize + DirectorySize(DirectoryID + 1, DirectoryName + Name + "\")
EndIf
EndIf
Wend
EndIf
ProcedureReturn TotalFileSize
EndProcedure
Debug DirectorySize(1, "C:\Windows\")