Added xargs option --no-run-if-empty 

to eliminate 
"dirname: missing operand
Try 'dirname --help' for more information."
errors that occur when the dirname is run with no options supplied.

See http://unix.stackexchange.com/questions/131592/blank-lines-when-executing-grep-xargs-in-a-find-exec for a way to do this with find that they say is safer.