代码点读机 / Python / os.mkdir

os.mkdir Python · 模块功能

新建一个空文件夹。

怎么用

import os
os.mkdir(path)

小例子

import os, tempfile
d = tempfile.mkdtemp()
os.mkdir(os.path.join(d, 'newdir'))
print(os.path.isdir(os.path.join(d, 'newdir')))

运行结果

True

提醒:父目录必须存在。

官方文档:https://docs.python.org/zh-cn/3/library/os.html#os.mkdir

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条