All pastes #491804 Raw Edit

123

public text v1 · immutable
·published 2007-05-16 21:13 UTC
rendered paste body
proc ::nxLib::GetDirStats {realPath varName {ignoreList ""} {firstCall 1}} {
    upvar $varName stats
    if {$firstCall} {
        array set stats [list DirCount 0 FileCount 0 TotalSize 0]
    }
    if {[file isdirectory $realPath]} {
        incr stats(DirCount)
        set listing [glob -nocomplain -directory $realPath "*"]
    } elseif {[file isfile $realPath]} {
        set listing [list $realPath]
    } else {return}

    foreach element $listing {
        if {[file readable $element] && ![ListMatchI $ignoreList [file tail $element]]} {
            if {[file isdirectory $element]} {
                GetDirStats $element stats $ignoreList 0
            } else {
                incr stats(FileCount)
                set stats(TotalSize) [expr {wide($stats(TotalSize)) + wide([file size $element])}]
            }
        }
    }
    return
}