#coding:utf-8
import os
import shutil

#将aaa.txt的内容复制到bbb.txt
shutil.copy('aaa.txt','bbb.txt')

#将aaa.txt复制到目录
shutil.copy('aaa.txt','./a')

#移动文件或目录
shutil.move('aaa.txt','bbb.txt')
shutil.move('aaa.txt','./a')
shutil.move('./b','./a')

#创建多级目录
if os.path.exists('./a/b/c') == False:
    os.makedirs('./a/b/c')

#删除目录,可以不为空
shutil.rmtree('./a')

if os.path.exists('./a/b/c/d') == False:
    os.makedirs('./a/b/c/d')

#复制一个目录a命名为b,目标b目录必须不存在
if os.path.exists('b') == False:
    shutil.copytree('a','b')

 

相关文章:

  • 2021-11-25
  • 2021-12-01
  • 2022-01-08
  • 2022-12-23
  • 2021-09-21
猜你喜欢
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-10-04
  • 2021-09-05
相关资源
相似解决方案