1、刪除目錄
import os
os.remove(path);
2墨状、刪除文件夾
import os
os.rmdir(path);
3卫漫、判斷目錄是否存在
import os
os.path.isdir(path)
# 存在返回True
4、判斷文件夾是否存在
import os
os.path.isfile(path)
# 存在返回True
5肾砂、獲取所有目錄中所有文件的名稱
import os
os.listdir(path)
# 存在返回返回名稱的集合
6列赎、復(fù)制拷貝文件
import shutil
shutil.copyfile("oldfile","newfile") # oldfile和newfile都只能是文件
shutil.copy("oldfile","newfile") # oldfile只能是文件夾,newfile可以是文件镐确,也可以是目標(biāo)目錄
7包吝、復(fù)制拷貝目錄
import shutil
shutil.copytree("olddir","newdir") # olddir和newdir都只能是目錄饼煞,且newdir必須不存在
8、重命名文件夾
import os
os.rename("oldname","newname") # 文件或目錄都是使用這條命令
9诗越、創(chuàng)建單個(gè)目錄
import os
os.mkdir(“test”
10砖瞧、創(chuàng)建多級目錄
import os
os.makedirs(r“c:\python\test”)