################################################################ # proc incrListElement {lstName position}-- # Increment the value at a given location in a list # Arguments # lstName Name of list # position Index of element to modify # Results # The list in the calling scope is modified. # proc incrListElement {lstName position} { upvar $lstName lst set tmp [lindex $lst $position] lset lst $position [incr tmp] } ################################################################ # proc fileSystemSummary {path pattern}-- # Returns a list of {depth subdirs files links unknown} # Arguments # path The file path to check # # Results # No side effects. Process is recursive. # proc fileSystemSummary {path} { set totals [list 0 0 0] foreach item [glob -nocomplain $path/*] { if {[file type $item] eq "directory"} { set lst [fileSystemSummary $item ] set newList {} foreach val1 $lst val2 $totals { lappend newList [expr {$val1 + $val2}] } set totals $newList incrListElement totals 0 } else { set type [file type $item] if {$type eq "file"} { # set tmp [lindex $lst 1] # lset lst 1 [incr tmp] incrListElement totals 1 } elseif {$type eq "link"} { incrListElement totals 2 } else { incrListElement totals 3 } } } return $totals } foreach count [fileSystemSummary [lindex $argv end]] \ type {Subdirs Files Links} { puts "$type: $count" }