Reputation: 83
I need to expand file specifications containing Perforce wildcards. I need this for local files on disk (not in the Perforce depot).
That is, I need something like the standard Python glob.glob()
that also understands the Perforce wildcard "...". For example:
>>> from p4glob import p4glob # The module I wish I had
>>> p4glob('....xml')
['a.xml', 'dir/b.xml', 'x/y/z/c.xml']
Does anybody have a module that can do this?
Upvotes: 1
Views: 321
Reputation: 3289
Also, if you have the latest release of Perforce you can do this with the P4Python equivalent of p4 status ....xml
.
Upvotes: 0
Reputation: 8617
Just use os.walk
and filter it.
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")]
Upvotes: 1