0

我有一个遍历目录并生成 md5sums 的 Python 程序。在一个文件上它卡住了。运行ls -lA我发现它有属性prw-------。一些谷歌搜索后我发现这表示管道。

如何检查我的遍历中的管道?我只想跳过这个文件。


我的遍历代码是:

for dirpath, _, files in walk(folder):
    for fname in files:
        print join(dirpath, fname)
        if not islink(join(dirpath, fname)):
            # do something with the file, here I pass it to myClass.
            myClass.addFile(dirpath, fname)
4

1 回答 1

2

您实际上并不需要明确地测试管道,您只想查找文件。

使用os.path.isfile();它将返回False管道,但返回True实际文件:

$ ls -l
total 0
-rw-rw-r-- 1 mj mj 0 Sep  7 12:27 actualfile
prw-rw-r-- 1 mj mj 0 Sep  7 12:25 pipe

>>> os.path.isfile('pipe')
False
>>> os.path.isfile('actualfile')
True
于 2013-09-07T11:26:26.207 回答