Move some code around for clarity.  Fix pathname generation when copying files from a subdirectory.