拷贝
# 拷贝文件
import shutil # 语法: shutil.copy(src, dst) '''示例 将 a 文件夹中的 a.txt 拷贝到 b 文件夹 ''' shutil.copy('a/a.txt', 'b')
# 拷贝文件夹 import shutil # 语法: shutil.copytree(src, dst) '''示例 将 a 文件夹 拷贝到 b 文件夹 ''' shutil.copytree('a', 'b')
移动、重命名
# 移动文件或文件夹 import shutil # 语法: shutil.move(src, dst) '''示例 将 a 文件夹中的 a.txt 移动到 b 文件夹中,并重命名为 12.txt ''' shutil.move('a/a.txt', 'b/12.txt')
删除
# 删除文件 import shutil # 语法: shutil.rmtree(path) '''示例 删除 a 文件夹及文件夹中的所有文件 ''' shutil.rmtree('a')