List Directories and Files with Tree

List Directories and Files with Tree

On one of our backup servers, we run StableBit’s DrivePool with great success. As we’ve mentioned, this is a great program that allows you to pool disparate hard drives on a Windows Desktop or Server and has some great features and options. We use it to simply pool a number of drives to provide a large (20+ TB) backup target for our uSANs. After all, it’s backup, and in a home lab, you may not want to spend extra money on parity drives in your backup server when you already have parity and redundancy at other levels. And though it’s been working without fail for some time now, there’s one nagging thought that always lurks in the shadows for me.

As with any virtual file system layered on top of a drive pool, not knowing exactly where your files are is just how things work. After all, that’s what it’s designed to do – obfuscate the disk subsystem to provide a single large file system to place your files. Copy your stuff to the pool and let the software do the rest. To the user, all your files transparently appear in one neat and tidy place.

Perhaps it’s my OCD, but I still like to know where everything is. In a pinch, say if a backup drive fails, I like knowing exactly what’s gone. It’s like the old saying, “you don’t know what you don’t know.” “But Bill,” you say, “if a disk fails, simply rerun your backup scripts and let the system do it’s thing.” I know, and you’re exactly right, but you still can’t convince my OCD of that.

So, without further ado, here’s a simple command-line tool in Windows that will output a list of your files for reference should you need it — tree. Tree is included with nearly all versions of Windows and it’s quite easy to use. In it’s simplest form, tree simply outputs a list of directories, beginning with the current directory, and does so in a visual tree form that shows the directory structure. In system32 for instance, it looks like this:

Tree only has a couple of command line switches, but both can be useful.  Running tree with /F also displays the names of the files in each folder. As you can imagine, the output could get quite lengthy for a folder like system32, but sending the output to a logfile allows you review or search the output as needed. Using the /A outputs the results using ASCII characters instead of extended characters.  This is important when sending the output to a plain-text file, in which extended characters may not appear properly.

The simple command just looks like this:

Output is neatly sent to a plain-text file, which documents the file and folder layout.

For our backup pool, we simply send the output tree to a log file as part of a daily scheduled task.  Should a drive in the pool fail, we can simply reference the log file for that day to determine exactly which files were lost.

2 thoughts on “List Directories and Files with Tree

Leave a Reply

Your email address will not be published. Required fields are marked *