Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. def batch_move(self, *args, **kwargs):
  2.   '''
  3.  Move a batch of files to its respective destinations.
  4.  Return type: tuple (boolean, message)
  5.                      T/F    , 'string' / str(exception)
  6.  '''
  7.  
  8.   srcs= kwargs.get('srcs', None)
  9.   dests = kwargs.get('dests', None)
  10.  
  11.   try:
  12.     if srcs and dests:
  13.        # map srcs and dests into dictionary (srcs --> keys, dests --> values)
  14.        src_dest= dict(zip(srcs, dests))    
  15.  
  16.        for src, dest in src_dest:
  17.          if os.path.exists(src):
  18.            if os.path.exists(dest):
  19.               shutil.rmtree(dest)
  20.            shutil.move(src, dest)   # either way we will proceed to move
  21.          else:
  22.            return (False, '%s does not exist!' % src)
  23.        return (True, 'Success!')
  24.  
  25.     else:
  26.        return (False, 'Something gone wrong with those kwargs...')
  27.   except Exception as e:
  28.     return (False, e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement