movefiles() now also checks that the complete path of a given destination path exists,

and attempts to create it if it does not. This is important in the case that the user specifies a folder parameter setting with subdirectories.
This commit is contained in:
Maxim Berezin 2018-07-26 15:45:34 -04:00
parent 48d42cd6b7
commit c8591757f1
1 changed files with 7 additions and 0 deletions

View File

@ -40,6 +40,13 @@ def movefiles(comicid, comlocation, imported):
logger.fdebug("Renaming files not enabled, keeping original filename(s)")
dstimp = os.path.join(comlocation, orig_filename)
if not os.path.exists(os.path.dirname(dstimp)):
logger.fdebug(os.path.dirname(dstimp) + ' does not exist - attempting to create...')
try:
os.makedirs(os.path.dirname(dstimp), int(mylar.CONFIG.CHMOD_DIR))
except (OSError, IOError):
logger.fdebug('Failed to create full directory path, but will try to move file anyway.')
logger.info("moving " + srcimp + " ... to " + dstimp)
try:
shutil.move(srcimp, dstimp)