Tree

class treefiles.Tree(name: Optional[Union[treefiles.tree.S, treefiles.tree.T, str]] = None, parent: Optional[treefiles.tree.T] = None)

Creates a tree instance

Parameters
  • name – root of the current tree

  • parent – parent tree if current tree is not the main root

abs(path='') treefiles.tree.S

Returns the absolute path of a tree root

Parameters

path – recursion parameter

property p: treefiles.tree.T

Returns the parent directory (path only)

__getattr__(att) Optional[Union[treefiles.tree.S, treefiles.tree.T, str]]

Finds an attribute

Parameters

att – the attribute name

The order of preferences is:
  • look for files at current level

  • look for child at current level

  • look in children levels recursively

__repr__(i=2)

Pretty prints th current tree

Parameters

i – recursion parameter

dir(*names: str, **named_dirs: str) treefiles.tree.T

Adds directories to the current level

Parameters

names – folder names

Returns

instance of the last child created

jdir(path: str, sep: str = '/') treefiles.tree.T

Create directory by joining path on sep

Parameters
  • sep – separator used in path

  • path – folder path, sperated by sep, joined to self.abs()

file(*args: str, **kwargs: str) treefiles.tree.T

Saves a filename at the current tree level

Parameters
  • args – filenames, attributes are the files basename

  • kwargs – filenames, attributes are the kwargs key

path(*args: str) treefiles.tree.S

Creates a path starting from parent

Parameters

args – paths to join

Returns

the joined absolute path

dump(clean: bool = False) treefiles.tree.T

Create tree as root (create folder and children)

Parameters

clean – remove root before recreating it if exists

Returns

root instance

remove_empty()

Deletes empty children

__getstate__()

Pickles an object.

Because of recursion on __getstate__, only the absolute path is saved when pickling for the moment. You can override this method if it does not meet your needs, PR are welcomed.

__setstate__(state)

Unpickles an object.

glob(pattern: str) List[treefiles.tree.S]

Return a list of paths matching a pathname pattern, see <glob.glob>

property ls

Returns a sorted list of the folder contents

pprint(comment=None, i=2)

Export the current tree to file with the tree format

Parameters
  • comment – File header

  • i – recursion parameter