1

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

也就是说,我需要标准 Python 之类的东西glob.glob(),它也能理解 Perforce 通配符“...”。例如:

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

有人有可以做到这一点的模块吗?

4

2 回答 2

1

只需使用os.walk并过滤它。

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")]
于 2012-05-08T00:09:21.683 回答
0

此外,如果您拥有最新版本的 Perforce,您可以使用 P4Python 等效的p4 status ....xml.

于 2012-05-08T15:01:40.280 回答