autodirs package

class autodirs.directories.Node(dir)

Bases: object

A class to create a tree node of the directories.

Parameters:dir – Name of the directory.
add_children(children)

Takes a list of child node which are instance of Node class. :param children: A list of child nodes of class Node.

as_path()

Creates a path of all the parent and child in the tree data structure.

Returns:A list of directory paths.
get_path()

Organises all the paths into one list

join_paths(dir, sub)

Takes a string and a list and makes a list. :param dir: The parent Node with the dir attribute. :param sub: A list of list containing all the child subdirectory.

Return paths:A list of all the paths in the directory structure.
autodirs.directories.create_directories_from_list(dir_list, path='', with_text=False)

Creates directory structure from the list provided.

Parameters:
  • dir_list – List of the subdirectories.
  • path – Path where the file structure must be created.
  • with_text – Boolean that makes a text file with the subdirectory name. (Default=False)
Example:
>>> import autodirs
>>> foo = ["bar", "baz"]
>>> autodirs.create_directories_from_list(dir_list=foo, path="sample_directories")
autodirs.directories.create_directories_from_text(sub_dir_names, path='', with_text=False)

Creates the sub directories inside a directory.

Parameters:
  • sub_dir_names – A text file with the list of the sub directories.
  • path – The file path to create the subdirectories from sub_dir_list (Default=””).
  • with_text – Boolean that makes a text file with the subdirectory name. (Default=False)
Raises:

TypeError – Missing positional arguments.

Example:
>>> import autodirs
>>> autodirs.create_directories_from_text(sub_dir_names="sample", path="sample_directories")
autodirs.directories.create_dirs_from_dict(dir_dict, root_path='')

Creates a directory structure followed by the directory structure.

Parameters:
  • dir_dict – Dictionary of dictionaries that suggest the directory structure.
  • root_path – Path where the directories must be created.
Example:
>>> import autodirs
>>> dir_dict = {'sub1': {'sub1_sub1': [], 'sub1_sub2': []}, 'sub2': {'sub2_sub1': []}, 'sub3': []}
>>> autodirs.create_dirs_from_dict(dir_dict)
autodirs.directories.create_nested_dirs_from_text(text, root_path='root')

Creates a complex directory structure from a text file.

Parameters:text – Path to the text file. (Example: example_text_file.txt)
Root_path:Path where the directories must be created.
Example:
>>> import autodirs
>>> autodirs.create_nested_dirs_from_text(text='textfile.txt', root_path='root')
autodirs.directories.dir_path_list(dirs, root_path='', list_dir=None)

Generates a list of all the directory paths from the dirs dictionary

Parameters:
  • dirs – A dictionary of complex directory structure where the last directory’s key has a value of an empty list.
  • root_path – A root path where the directory structure must be created. (Default=’’)
  • list_dir – A list that is None and not yet assigned.
Returns list_dir:
 

A list of all the directory paths.

Example:
>>> import autodirs
>>> foo_dict = {'sub1': {'sub1_sub1': [], 'sub1_sub2': []}, 'sub2': {'sub2_sub1': []}, 'sub3': []}
>>> foo_list = autodirs.dir_path_list(foo_dict, root_path='main')
>>> print(foo_list)
['main/sub1/sub1_sub1', 'main/sub1/sub1_sub2', 'main/sub2/sub2_sub1', 'main/sub3']
autodirs.directories.group_by_text_files(text_path, path='', with_text=False)

Creates directory structure to the set path from a group of text files. The text_path file name forms the directory in the root of the path. The list inside the text files form the sub directories.

Parameters:
  • text_path – path where the text files are located.
  • path – path where the directories must be created.
  • with_text – Boolean that makes a text file with the subdirectory name. (Default=False)
Example:
>>> import autodirs
>>> autodirs.group_by_text_files(text_path="text_path", path="sample_directories")