Fixed bugs with directory copy.

Several bugs that were uncaught by the tests include undefined
variables, and an invalid invocation of os.makedirs