Lots of bug fixes. Script mostly works now. Db changes are not commited until the very end, so if the script aborts no changes are made to the db. However, if the script aborts after a copy operation, the orphaned files will be left in the library but not in the db. Should probably fix this.