install shutil
pip install pytest-shutil
python copy file
from shutil import copyfile
copyfile(src, dst)
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))
# create the folders if not already exists
os.makedirs(target)
# adding exception handling
try:
shutil.copy(source, target)
except IOError as e:
print("Unable to copy file. %s" % e)
except:
print("Unexpected error:", sys.exc_info())
shutil
The shutil module offers a number of high-level operations on files and
collections of files. In particular, functions are provided which
support file copying and removal. For operations on individual files,
see also the os module.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us