Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def batch_move(self, *args, **kwargs):
- '''
- Move a batch of files to its respective destinations.
- Return type: tuple (boolean, message)
- T/F , 'string' / str(exception)
- '''
- srcs= kwargs.get('srcs', None)
- dests = kwargs.get('dests', None)
- try:
- if srcs and dests:
- # map srcs and dests into dictionary (srcs --> keys, dests --> values)
- src_dest= dict(zip(srcs, dests))
- for src, dest in src_dest:
- if os.path.exists(src):
- if os.path.exists(dest):
- shutil.rmtree(dest)
- shutil.move(src, dest) # either way we will proceed to move
- else:
- return (False, '%s does not exist!' % src)
- return (True, 'Success!')
- else:
- return (False, 'Something gone wrong with those kwargs...')
- except Exception as e:
- return (False, e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement