Page 2 of 2

Demivec

Posted: Sun Aug 24, 2008 5:30 pm
by dannyboy99
i have pm you

Posted: Mon Aug 25, 2008 2:08 pm
by Demivec
harff182 wrote:There is an example in the Codearchiv:

Code: 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")
dannyboy99 wants mbs :lol:, so change the last line:
Debug Str(GetDirectorySize("C:\Windows")/1024/1024) + " mbs"
The code is incorrect, it should read as:

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")
It should now return the correct value for the size.