python shutil copy copyfile code example
Example 1: shutil copy python
import os
import shutil
source = 'current/test/test.py'
target = '/prod/new'
assert not os.path.isabs(source)
target = os.path.join(target, os.path.dirname(source))
os.makedirs(target)
try:
shutil.copy(source, target)
except IOError as e:
print("Unable to copy file. %s" % e)
except:
print("Unexpected error:", sys.exc_info())
Example 2: shutil copyfile python
source = "/home/User/Documents/file.txt"
destination = "/home/User/Documents/file(copy).txt"
dest = shutil.copyfile(source, destination)