mca*_*dre 281
您可以使用os.makedirs()创建一个文件夹,
并使用os.path.exists()来查看它是否已存在:
newpath = r'C:\Program Files\arbitrary'
if not os.path.exists(newpath):
os.makedirs(newpath)
Run Code Online (Sandbox Code Playgroud)
如果您正在尝试制作安装程序:Windows Installer会为您做很多工作.
Jue*_*gen 36
你试过os.mkdir吗?
您也可以尝试这个小代码片段:
mypath = ...
if not os.path.isdir(mypath):
os.makedirs(mypath)
Run Code Online (Sandbox Code Playgroud)
如果需要,makedirs会创建多个级别的目录.
Ale*_*lli 36
你可能想要os.makedirs,因为它会创建中间目录,如果需要的话.
import os
#dir is not keyword
def makemydir(whatever):
try:
os.makedirs(whatever)
except OSError:
pass
# let exception propagate if we just can't
# cd into the specified directory
os.chdir(whatever)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
421378 次 |
| 最近记录: |