Megabtyes

Just starting out? Need help? Post your questions and find answers here.
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Demivec

Post by dannyboy99 »

i have pm you
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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.
Post Reply