[GRASS-user] List files and count

Glynn Clements glynn at gclements.plus.com
Mon Jan 10 11:03:35 EST 2011

António Rocha wrote:

> I need to find, in a certain mapset, a list of files with a name that 
> match a certain string and count them. How can I do this? I'm 
> implementing this in a Py Script

grass.script.mlist() provides an interface to g.mlist, although it
only supports glob patterns and not regexps. If you need regexps:

def mlist(type, pattern = None, mapset = None):
    result = list()
    for line in read_command("g.mlist",
                             flags = 'r',
                             type = type,
                             pattern = pattern,
                             mapset = mapset).splitlines():
    return result

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-user mailing list