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")