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())
1The shutil module offers a number of high-level operations on files and
2collections of files. In particular, functions are provided which
3support file copying and removal. For operations on individual files,
4see also the os module.