
在Python的模块的中,有没有办法找到一个目录是否存在,如:
>>> os.direxists(os.path.join(os.getcwd()), 'new_folder')) # in pseudocode
True/False
您正在寻找[ ` os.path.isdir
代码> ](http://docs.python.org/dev/library/os.path.html#os.path.isdir)或[ os.path.exists代码>](http://docs.python.org/dev/library/os.path.html#os.path.exists),如果你不在乎它是一个文件还是一个目录。
示例:
import os
print(os.path.isdir("/home/el"))
print(os.path.exists("/home/el/myfile.txt"))
那么近! os.path.isdir返回True,如果你传入一个当前存在的目录的名字。如果它不存在或不是目录,则返回False。
未经作者同意,本文严禁转载,违者必究!




近期评论