def gettree(lp: LocalPath): assert lp.check() if lp.isdir(): return {df.basename: gettree(df) for df in lp.listdir()} elif lp.isfile(): return lp.read_text("utf8") else: raise Exception("not directory or file: {}".format(lp))
def gettree(lp: LocalPath, max_len=120): """ Get a dict representing the file tree for a directory """ assert lp.check() if lp.isdir(): return {df.basename: gettree(df, max_len=max_len) for df in lp.listdir()} else: assert lp.isfile() content = lp.read_text('utf8') if max_len and len(content) > max_len: content = content[:max_len - 3] + '...' return content