Fixed bug where output went to wrong directories.

Needed to use last component of input directory, not the entire path
name.