Page 2 of 2

Posted: Sun Oct 23, 2005 1:58 pm
by Droopy
Try this :

Code: Select all

;/ Return Size of a Directory ( in Kb )

Procedure SearchDirectorySize(Path.s)
  
  ; Add \ to Path if missing
  If Right(Path,1)<>"\" : Path+"\":EndIf
  
  ; Apply Structure
  lpFindFileData.WIN32_FIND_DATA
  
  ; Add Filter *.*
  Recherche.s=Path+"*.*"
  
  ; Initiate the Search
  handle.l = FindFirstFile_(Recherche, @lpFindFileData)
  
  ; If search succeeds
  If handle <> #INVALID_HANDLE_VALUE
    
    Repeat
      
      ; Trouve = File or Directory Found
      Trouve.s=PeekS(@lpFindFileData\cFileName)
      
      ; This is a not a directory
      If lpFindFileData\dwFileAttributes & #FILE_ATTRIBUTE_DIRECTORY =#False
        
        Fichiers.s=Path+Trouve
        
        Size+( lpFindFileData\nFileSizeLow / 1024) ; Add Low DWord
        If lpFindFileData\nFileSizeHigh
          Size+lpFindFileData\nFileSizeHigh * $3FFFFF ; Add High DWord *$3FFFFF
        EndIf
        
      EndIf
      
      ; Exit when there is no more files
    Until FindNextFile_(handle, @lpFindFileData)= #False
    
    ; Close the Api search Function
    FindClose_(handle)
    
  EndIf

  ProcedureReturn Size
  
EndProcedure
  
Procedure SearchSubDirectorySize(Path.s)
  
  ; Add \ to Path if missing
  If Right(Path,1)<>"\" : Path+"\":EndIf
  
  ; Apply Structure
  lpFindFileData.WIN32_FIND_DATA
  
  ; Add Filter *.*
  Recherche.s=Path+"*.*"
  
  ; Initiate the Search
  handle.l = FindFirstFile_(Recherche, @lpFindFileData)
  
  ; If search succeeds
  If handle <> #INVALID_HANDLE_VALUE
    
    Repeat
      
      ; trouve = File Or Directory Found
      Trouve.s=PeekS(@lpFindFileData\cFileName)
      
      ; This is a directory
      If lpFindFileData\dwFileAttributes & #FILE_ATTRIBUTE_DIRECTORY
        
        ; And not the . or .. directory
        If Trouve <>"." And Trouve <>".."
          
          ; Call the function itself ( Recursive ) to search in another Directory
          Size+SearchSubDirectorySize(Path+Trouve)
          
          ; Directory found : Search file within this Directory
          Size+ SearchDirectorySize(Path+Trouve)
          
        EndIf
        
      EndIf
      
      ; Exit when there is no more files
    Until FindNextFile_(handle, @lpFindFileData)= #False
    
    ; Close the Api search Function
    FindClose_(handle)
    
  EndIf

  ProcedureReturn Size
  
EndProcedure

ProcedureDLL GetDirectorySize(Path.s) 
  
  Size=SearchDirectorySize(Path) ; Car le répertoire lui même n'est pas scanné sinon
  Size+SearchSubDirectorySize(Path)
  
  ProcedureReturn Size
  
EndProcedure

;/ Test
#Directory="c:\Windows\"
MessageRequester(#Directory,Str(GetDirectorySize(#Directory))+" Kb")

Posted: Thu Jan 05, 2006 12:00 am
by trather
That works great. That is what I was looking for. Sorry it took me so long to get back to you but life got in the way of programing. 8)

Posted: Thu Jan 05, 2006 1:10 am
by Droopy
No problemo 8)

Posted: Thu Jan 05, 2006 1:35 am
by NoahPhense
Very nice..

- np

** oops .. you have the package somewhere in non-installer form?

Posted: Thu Jan 05, 2006 7:11 am
by Droopy

Posted: Thu Jan 05, 2006 1:58 pm
by NoahPhense
Thanks man.. appreciated..

- np