Page 1 of 1

Filesystem funcs and du do not seem to match

Posted: Thu Jul 31, 2008 4:57 pm
by mdp
Can anybody explain why the PB filesystem funcs and the "du" command do not return the same values?

A procedure:

Code: Select all

Procedure GetFolderSize( dir.s )
   dh=ExamineDirectory(#PB_Any,dir,"*") : If dh
      While NextDirectoryEntry(dh)
         nm.s=DirectoryEntryName(dh) 
         If DirectoryEntryType(dh)=#PB_DirectoryEntry_Directory
            If nm<>"." And nm<>".." 
               sz=sz+GetFolderSize(dir+"/"+nm) : Debug dir+"/"+nm+" "+Str(sz) 
            EndIf
         Else
            sz=sz+DirectoryEntrySize(dh)
         EndIf
       Wend  
      If IsDirectory(dh) : FinishDirectory(dh) : EndIf
   Else
      ;PrintN("No dir!")
   EndIf
   ProcedureReturn sz
EndProcedure

Debug GetFolderSize("/home")
does not return the same as

Code: Select all

du -b
Examples:
checking the purebasic folder size returns 22643082 with the above function, 23118218 with du
[...]/purebasic/examples/sources/data should be 875469 for the above, 879565 for du

Posted: Thu Jul 31, 2008 9:25 pm
by freak
du prints "estimated file space usage". I think it includes space for the directory table entries for the files as well.
"du -b" in an empty directory prints 4096 for example.

The DirectoryEntrySize() output matches what "ll" prints for the individual files, so it should be correct.