python目录操作shutil

#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')
原文地址:https://www.cnblogs.com/yuuwee/p/5685182.html