Python glob for Perforce文件规范通配符

2024-04-16 18:02:49 发布

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

我需要扩展包含Perforce通配符的文件规范。我需要这个用于磁盘上的本地文件(不在Perforce仓库中)。在

也就是说,我需要一些类似于标准Python glob.glob()的东西,它还可以理解perce通配符“…”。例如:

>>> from p4glob import p4glob        # The module I wish I had
>>> p4glob('....xml')
['a.xml', 'dir/b.xml', 'x/y/z/c.xml']

有人有能做到这一点的模块吗?在


Tags: 文件thefromimport规范标准xmlglob
2条回答

另外,如果您有Perforce的最新版本,那么您可以使用P4Python等效的p4 status ....xml来实现这一点。在

只需使用^{}并过滤它。在

import os

def p4glob(ext, startdir='.'):
    for root, dirs, files in os.walk(startdir):
        for f in files:
            # whatever filter params you need. e.g:
            if f.endswith(ext):
                yield os.path.join(root, f)
                # or append to an output list if you dont want a generator

# usage
[i for i in p4glob(".xml")]

相关问题 更多 >