复制文件shutil.copy(source, destination)
shutil.copy(source, destination)将source处的文件复制到路径destination 处的文件夹。
os.chdir('C:\\')
# part1 文件夹存在时,hello.txt 被复制到 C:\part1 中
# part1 文件夹不存在时,hello.txt 被复制为 part1 文件,没有 .txt 后缀
shutil.copy('hello.txt', 'part1')
# helloworld.txt 不存在时,hello.txt 被复制,名为 helloworld.txt
# helloworld.txt 存在时,helloworld.txt 被 hello.txt 覆写
shutil.copy('hello.txt','helloworld.txt')
复制文件夹shutil.copytree(source, destination)
shutil.copytree(source, destination)复制整个文件夹,以及它包含的文件夹和文件。