Tag Archives: directory listing

Print a Hierarchical List of Disk Contents

VFX companies often include paper printouts of a hard drive’s contents when they send material to/from Production, the DI, and other vendors. Occasionally, it’s useful for Editorial departments to do the same. Having a printout attached to a hard drive you’re sending out lets your vendor see exactly what’s on the drive without having to plug it in, and can be used to log a drive in or catalog it while it’s offline.

Strangely, there’s a lack of software available to do such a simple task as printing a directory listing. Searching through Google, I found a few applications for OSX that offered this functionality, but either the application wasn’t exaclty what I was looking for, or it added too many flourishes like icons and such.

So, I turned to the Terminal. Using a pattern I found in a forum on Unix.com, I modified the arguments and incorporated it into an Automator workflow (attached). This workflow displays a recursive list of directories (if you want only files or both files and directories see the bottom of this post), and is broken into the following steps:

  1. Asks for the root folder you’d like to make a listing from. This would usually be the root of your external hard drive.
  2. Asks how many levels of recursion you’d like.
    • Example: In one instance I was backing up P2 cards. I only needed to list the folder name of each P2 card I was including, and not the CONTENTS, VIDEO, VOICE, PROXY, ICON, and AUDIO folders that exist as subfolders of a P2 card’s root directory. So using this function with a recursion level of 2, my printout stopped processing directories after 2 levels of hierarchy.
  3. Runs the shell command:
find "$2" -type d -maxdepth $1 ! -name '.*' -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<2  && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}'  FS='/'
  1. Saves a text file with the listing in the same directory you chose in Step 1, and then opens that file so you can browse and print it.

The output looks like this:

|      |---Warrior Back Up
|      |              |---Dailies by Tape
|      |              |              |---CT001
|      |              |              |---HI-8
|      |              |              |---VT001
|      |              |              |---VT002
|      |              |              |---VT003
|      |              |              |---VT004
|      |              |              |---VT005
|      |              |              |---VT006
|      |              |              |---VT007
|      |              |              |---VT008
|      |              |              |---VT009
|      |              |---P2 Backup
|      |              |        |---MISC
|      |              |        |---PRODUCTION
|      |              |        |---REHEARSAL FIGHTS
|      |              |        |---TESTS

Future Refinements

Suggestions welcome, but things I'm already thinking to add to this workflow later on are:

  1. An option to show files as well as folders. You can change this in the workflow yourself by changing "-type d" to "-type f" for a files-only listing, or remove "-type d" completely for both files and folders.
  2. A dialogue to ask if you want to print the listing automatically