Jump to content

Get folder size but with exceptions


Recommended Posts

Wondering if there is a way of getting the total size of a folder while providing and exception list of sub folders i don't want to be included in the final count.

For example I have a folder z:\Builds. Within 'Builds' there are many sub folders however in each sub folder there is a folder called archive.

I want each archive folder from each sub folder to be included in the folder size of z:\builds.

Hope this make sense

Can anyone help?

Link to comment
Share on other sites

  • Moderators

vickerps,

Search using the keywords "+recursive +search". There are many scripts out there which will list the subfolders in path. Once you have the list of subfolders, run through it and use DirGetSize on those you want to include in the total.

Give it a try and come back if you run into problems. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Try this adjusted version of my _DirGetSizeEx() UDF...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         KaFu
 Script Name, Version and Date: _DirGetSizeEx v04 (09-Jan-22)
 http://www.autoitscript.com/forum/index.php?showtopic=88094&view=findpost&p=699650

 Script Function:
    _DirGetSizeEx, a replacement for DirGetSize()
    UDF using AU native functions only. Faster than DirGetSize() in the inital run on XP, slower in a repeated run, DirGetSize seems to cache the result.
    Change $Path between tests to seem what I mean.

    DirGetSize can not be interrupted / stopped, that's the main reason I coded this UDF

    Function returns an array
    $array[0] = Bytes
    $array[1] = File Count
    $array[2] = Folder Count

    @error = 1, max. recursion level of 5100 exceeded, directory structure too deep

    On Vista DirGetSize seems to be much faster than on XP, thus if you're only into speed use something like:

    if @OSVersion <> "WIN_VISTA" Then
        $aResult = _DirGetSizeEx($Path)
    Else
        $aResult = DirGetSize($Path)
    EndIf

    But keep in mind, main advantage of _DirGetSizeEx is that during runtime you can easily implement a progress count or interrupt the function with
    a global variable (like I do in SMF, just define a bool something like $running = true and switch it with WM_COMMAND)

#ce ----------------------------------------------------------------------------

Dim $Path = "z:\Builds"
Global $dirKeyWord = "archive"

$a_DirGetSizeEx = _DirGetSizeEx($Path)  ; <= recommended

MsgBox(0, '_DirGetSizeEx()', '' _
        & '_DirGetSizeEx()' & @crlf &  'Bytes: ' & $a_DirGetSizeEx[0] & @crlf & 'File Count: ' & $a_DirGetSizeEx[1] & @CRLF & 'Folder Count: ' & $a_DirGetSizeEx[2] & @CRLF & @CRLF)

Func _DirGetSizeEx($sPath = @ScriptDir)
    Local $sSearch, $aResult_sub[3]
    Local $aResult[3] = [0,0,0]
    if Not IsDeclared("iDirGetSizeExRecursionLevel") then
        Global $iDirGetSizeExRecursionLevel = 1
    Else
        $iDirGetSizeExRecursionLevel += 1
    endif
    if $iDirGetSizeExRecursionLevel = 5099 Then
        SetError(1)
        Return
    endif

    If StringRight($sPath, 1) <> "\" Then $sPath &= "\" ; Ensure $sPath has a trailing slash
    $sSearch = FileFindFirstFile($sPath & "*.*")
    While 1
        $sNext = FileFindNextFile($sSearch) ; check if next file can be found, otherwise exit loop
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($sPath & $sNext & "\"), "D") Then
            if $sNext = $dirKeyWord or StringInStr($sPath & $sNext,"\" & $dirKeyWord & "\") then $aResult[2] += 1
            $aResult_sub = _DirGetSizeEx($sPath & $sNext)
            if @error then
                SetError(@error)
                Return
            endif
            $aResult[0] += $aResult_sub[0]
            $aResult[1] += $aResult_sub[1]
            $aResult[2] += $aResult_sub[2]
        Else
            if not StringInStr($sPath & $sNext,"\" & $dirKeyWord & "\") then ContinueLoop
                $aResult[1] += 1
                $aResult[0] += FileGetSize($sPath & $sNext)
        EndIf
    WEnd
    FileClose($sSearch)
    Return $aResult
EndFunc   ;==>_DirGetSizeEx
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...