【文件复制】
python中没有直接复制文件的内置函数
但可以通过读取一个文件的内容,并将其写入另一个新文件来实现:复制功能
def copy_file(src,dst):
with open(src, 'rb') as source_file,open(dst,"wb") as destination_file:
destination_file.write(source_file.read())
#使用示例
copy_file("./data/test.txt",'./data/testCopy.txt')
【文件移动和重命名】
os模块的rename函数来移动或者重命名文件
import os
def move_file(src,dst):
os.rename(src,dst)
#使用示例
move_file('./data/testCopy.txt','./moveFile/newTestCopy.txt')