print_directory_tree#
- tensordict.utils.print_directory_tree(path, indent='', display_metadata=True) str#
Logs the tree of files and directories under
path.Each line is logged at the
INFOlevel with the tensordict logger (tensordict.utils.logger) and the tree is returned as a string. The entries of a directory are in the order ofos.listdir().- Parameters:
- Returns:
The lines that were logged, joined by newlines.
Examples
>>> import tempfile >>> import torch >>> from tensordict import TensorDict >>> from tensordict.utils import print_directory_tree >>> td = TensorDict(a=torch.zeros(3), b=torch.ones(3), batch_size=[3]) >>> with tempfile.TemporaryDirectory() as path: ... _ = td.memmap(path) ... tree = print_directory_tree(path, display_metadata=False) >>> sorted(line.strip() for line in tree.splitlines()[1:]) ['a.memmap', 'b.memmap', 'meta.json']