1,os.mkdir()
只能创建一个不存在的目录
2,os.makedirs()
递归地创建多个不存在的目录
import os
pth = r"dir1" # dir1不存在
if not os.path.exists(pth):
os.mkdir(pth)
import os
pth = r"dir2/dir3" # dir2, dir3都不存在
if not os.path.exists(pth):
os.mkidr(pth)
1,os.mkdir()
只能创建一个不存在的目录
2,os.makedirs()
递归地创建多个不存在的目录
import os
pth = r"dir1" # dir1不存在
if not os.path.exists(pth):
os.mkdir(pth)
import os
pth = r"dir2/dir3" # dir2, dir3都不存在
if not os.path.exists(pth):
os.mkidr(pth)