如何在python中检查文件是目录文件还是常规文件?

2024-04-26 11:42:41 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
How to identify whether a file is normal file or directory using python

如何检查路径是python中的目录还是文件?


Tags: or文件to路径目录isdirectoryhow
3条回答

使用os.path.isdir(path)

更多信息请点击http://docs.python.org/library/os.path.html

许多Python目录函数都在^{} module中。

import os
os.path.isdir(d)
os.path.isfile("bob.txt") # Does bob.txt exist?  Is it a file, or a directory?
os.path.isdir("bob")

相关问题 更多 >