'A recursive generator of files.'

def ListDirectory(self, pathspec, state, depth=0):

    if (depth >= self.request.max_depth):
        return
    try:
        fd = vfs.VFSOpen(pathspec, progress_callback=self.Progress)
        files = fd.ListFiles()
    except (IOError, OSError) as e:
        if (depth == 0):
            self.SetStatus(rdf_flows.GrrStatus.ReturnedStatus.IOERROR, e)
        else:
            logging.info('Find    failed    to    ListDirectory    for    %s.    Err:    %s', pathspec, e)
        return
    if ((not self.request.cross_devs) and (self.filesystem_id is None)):
        dir_stat = fd.Stat()
        self.filesystem_id = dir_stat.st_dev
    start = state.get(pathspec.CollapsePath(), 0)
    for (i, file_stat) in enumerate(files):
        if (i < start):
            continue
        if stat.S_ISDIR(file_stat.st_mode):
            if (self.request.cross_devs or (self.filesystem_id == file_stat.st_dev)):
                for child_stat in self.ListDirectory(file_stat.pathspec, state, (depth + 1)):
                    (yield child_stat)
        state[pathspec.CollapsePath()] = (i + 1)
        (yield file_stat)
    try:
        del state[pathspec.CollapsePath()]
    except KeyError:
        pass
