_Example1() _Example2() Func _Example1() Local $iDocSize = _DirGetSizeByExtension(@MyDocumentsDir, "doc") ConsoleWrite("Size of all .doc files in """ & @MyDocumentsDir & """ : " & $iDocSize & " bytes" & @CRLF) EndFunc Func _Example2() Local $hTimer1=TimerInit() Local $aSize1 = _DirGetSizeByExtension(@AppDataDir, "*", 1) Local $iDiff1=TimerDiff($hTimer1)/1000 Local $hTimer2=TimerInit() Local $aSize2 = DirGetSize(@AppDataDir, 1) Local $iDiff2=TimerDiff($hTimer2)/1000 ConsoleWrite(@CRLF & "_DirGetSizeByExtension / DirGetSize :" & @CRLF) ConsoleWrite("Size :" & $aSize1[0] & " / " & $aSize2[0] & @CRLF) ConsoleWrite("Files count :" & $aSize1[1] & " / " & $aSize2[1] & @CRLF) ConsoleWrite("Folders count :" & $aSize1[2] & " / " & $aSize2[2] & @CRLF) ConsoleWrite("Time :" & $iDiff1 & " / " & $iDiff2 & @CRLF) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DirGetSizeByExtension ; Description ...: Returns the size in bytes of a file list by extension. ; Syntax ........: _DirGetSizeByExtension($sDir[, $sExt = "*"[, $iFlag = 0]]) ; Parameters ....: $sDir - The directory to search in. ; $sExt - [optional] Extension of files to serch for. Default is "*" (all extensions). ; $iFlag - [optional] 0 (default) = Returns the size ; 1 = Extended mode is On -> returns an array that contains extended information (see Remarks). ; Return values .: Success = The size in bytes, or a single dimension array ; Failure = -1 and sets the @error flag to 1 if the path doesn't exist. ; Author ........: jguinch ; Remarks .......: If you use the extended mode then the array returned from this function is a single dimension array containing the following elements: ; $aArray[0] = Size ; $aArray[1] = Files count ; $aArray[2] = Dirs Count ; =============================================================================================================================== Func _DirGetSizeByExtension($sDir, $sExt = "*", $iFlag = 0) If NOT FileExists($sDir) Then Return SetError(1, 0, -1) If NOT StringInStr(FileGetAttrib($sDir), "D") Then Return SetError(1, 0, -1) If $sExt = "*" Then $sExt = "?.*" Local $aDirs[1] = [ StringRegExpReplace($sDir, "\\$", "") ] Local $iCountDir = 0, $iCountFile = 0, $n = 0 Local $hSearch, $sFileName Local $iSize = 0 While 1 $hSearch = FileFindFirstFile( $aDirs[$n] & "\*.*" ) If $hSearch <> -1 Then While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If @Extended Then $iCountDir += 1 If $iCountDir >= UBound($aDirs) Then Redim $aDirs[ UBound($aDirs) * 2] $aDirs[$iCountDir] = $aDirs[$n] & "\" & $sFileName Else If StringRegExp($sFileName, "(?i)\." & $sExt & "$") Then $iSize += FileGetSize($aDirs[$n] & "\" & $sFileName) $iCountFile += 1 EndIf EndIf WEnd EndIf FileClose($hSearch) If $n = $iCountDir Then ExitLoop $n += 1 WEnd If NOT $iFlag Then Return $iSize Local $aResult[3] = [ $iSize, $iCountFile, $iCountDir ] Return $aResult EndFunc