March 24, 2009 /
by Jeffery Hicks /
Up a Tree
One of the first CMD commands I fell in love with (yes I’m that geeky) was TREE. When executed from a command prompt it would give you a nice graphical representation of the directory structure. Never being satisfied I wrote a VBScript version years ago. I decided to dust it off and tweak it some. Here is TREE.VBS.
The folder size is formatted in KB. Now the fun part. I have a subroutine that takes a level indicator and a path as parameters.
The subroutine increments the tab level by one and then returns a collection of subfolders.
nTabLevel = nTabLevel +1
ForEach folder In colSubs
For each subfolder I create a tree indicator using something like |_____ before the folder name. The length of the underscore and indentation is determined by the level the script is processing.
WScript.Echo String(nTabLevel," ") & "|" &_
String(nTabLevel,"_") & folder.name &_
" (" & colFiles.count & " files " &_
FormatNumber(folder.size/1024,2) & " KB)"
The display includes the foldername, how many files it has and total size. These values are only for the files immediately within the folder. To keep going I recursively call the function for any subfolders.
'recurse through subfolders
After processing any subfolders, the level counter is decremented by 1.
The script will ignore any folders it can’t access. Vista is notoriously difficult for this sort of thing with all of its junction points so don’t take this output as 100% accurate. Still, I think is fun. Did I mention I’m kinda geeky?