Megabtyes
The code is incorrect, it should read as:harff182 wrote:There is an example in the Codearchiv:dannyboy99 wants mbsCode: Select all
Procedure.q GetDirectorySize(path.s, size.q=0) Protected dir.l=ExamineDirectory(#PB_Any, path, "") If dir While NextDirectoryEntry(dir) If DirectoryEntryType(dir) = #PB_DirectoryEntry_File size+DirectoryEntrySize(dir) ElseIf Not DirectoryEntryName(dir) = "." And Not DirectoryEntryName(dir) = ".." GetDirectorySize(path+DirectoryEntryName(dir)+"", size) EndIf Wend FinishDirectory(dir) EndIf ProcedureReturn size EndProcedure Debug GetDirectorySize("C:\Windows")
, so change the last line:
Debug Str(GetDirectorySize("C:\Windows")/1024/1024) + " mbs"
Code: Select all
;Procedure.q GetDirectorySize(path.s, size.q=0) ;<== size parameter is unnecessary
Procedure.q GetDirectorySize(Path.s)
Protected Size.q, dir.l = ExamineDirectory(#PB_Any, Path, "")
If dir
While NextDirectoryEntry(dir)
If DirectoryEntryType(dir) = #PB_DirectoryEntry_File
Size + DirectoryEntrySize(dir)
ElseIf Not DirectoryEntryName(dir) = "." And Not DirectoryEntryName(dir) = ".."
;GetDirectorySize(path+DirectoryEntryName(dir)+"", size)
Size + GetDirectorySize(Path + DirectoryEntryName(dir) + "") ;<== new line adds the return value to the current total
EndIf
Wend
FinishDirectory(dir)
EndIf
ProcedureReturn Size
EndProcedure
Debug GetDirectorySize("C:\Windows")