DataUtils.FolderWalker

DataUtils.FolderWalker#

DataUtils.FolderWalker.py

Utility functions to walk through folders and find those containing specific data files.

default_iswanted(nodes)#

Determine if a folder is wanted based on the presence of .dat files. A folder is considered wanted if it contains more than 10 .dat files.

Parameters:

nodes (list of str) – List of file and folder names in the directory.

Returns:

True if the folder is wanted, False otherwise.

Return type:

bool

default_filter(folder)#

Default filter to exclude folders with ‘_micro’ in their names.

Parameters:

folder (str) – The folder path.

Returns:

True if the folder is wanted, False otherwise.

Return type:

bool

walk_folders(folder, level=0, depth=3, iswanted=<function default_iswanted>, filter=<function default_filter>)#

Walk through folders up to a certain depth and yield those that are wanted.

Parameters:
  • folder (str) – The root folder to start walking from.

  • level (int, optional) – The current depth level (default is 0).

  • depth (int, optional) – The maximum depth to walk (default is 3).

  • iswanted (function, optional) – A function that takes a list of nodes and returns True if the folder is wanted (default is default_iswanted).

  • filter (function, optional) – A function that takes a folder path and returns True if the folder should be excluded (default is default_filter).

Yields:

str – The path of the wanted folder.