1import os
2import shutil
3
4source = 'current/test/test.py'
5target = '/prod/new'
6
7assert not os.path.isabs(source)
8target = os.path.join(target, os.path.dirname(source))
9
10# create the folders if not already exists
11os.makedirs(target)
12
13# adding exception handling
14try:
15 shutil.copy(source, target)
16except IOError as e:
17 print("Unable to copy file. %s" % e)
18except:
19 print("Unexpected error:", sys.exc_info())