nexusLIMS.utils.files#
File finding and manipulation utilities for NexusLIMS.
Module Contents#
Functions#
Find directories modified between two times. |
|
Find files motified between two times. |
|
Find files modified between two times. |
API#
- nexusLIMS.utils.files.find_dirs_by_mtime(path: str, dt_from: datetime, dt_to: datetime, *, followlinks: bool = True) List[str][source]#
Find directories modified between two times.
Given two timestamps, find the directories under a path that were last modified between the two.
Deprecated since version 0.0.9:
find_dirs_by_mtimeis not recommended for use to find files for record inclusion, because subsequent modifications to a directory (e.g. the user wrote a text file or did some analysis afterwards) means no files will be returned from that directory (because it is not searched)- Parameters:
path – The root path from which to start the search
dt_from – The “starting” point of the search timeframe
dt_to – The “ending” point of the search timeframe
followlinks – Argument passed on to py
os.walk()to control whether symbolic links are followed
- Returns:
dirs – A list of the directories that have modification times within the time range provided
- Return type:
- nexusLIMS.utils.files.find_files_by_mtime(path: Path, dt_from, dt_to) List[Path][source]#
Find files motified between two times.
Given two timestamps, find files under a path that were last modified between the two.
- Parameters:
- Returns:
files – A list of the files that have modification times within the time range provided (sorted by modification time)
- Return type:
- nexusLIMS.utils.files.gnu_find_files_by_mtime(path: Path, dt_from: datetime, dt_to: datetime, extensions: List[str] | None = None, *, followlinks: bool = True) List[Path][source]#
Find files modified between two times.
Given two timestamps, find files under a path that were last modified between the two. Uses the system-provided GNU
findcommand. In basic testing, this method was found to be approximately 3 times faster than usingfind_files_by_mtime()(which is implemented in pure Python).- Parameters:
path – The root path from which to start the search, relative to the NX_INSTRUMENT_DATA_PATH environment setting.
dt_from – The “starting” point of the search timeframe
dt_to – The “ending” point of the search timeframe
extensions – A list of strings representing the extensions to find. If None, all files between are found between the two times.
followlinks – Whether to follow symlinks using the
findcommand via the-Hcommand line flag. This is useful when the NX_INSTRUMENT_DATA_PATH is actually a directory of symlinks. If this is the case andfollowlinksisFalse, no files will ever be found because thefindcommand will not “dereference” the symbolic links it finds. See comments in the code for more comments on implementation of this feature.
- Returns:
A list of the files that have modification times within the time range provided (sorted by modification time)
- Return type:
List[str]
- Raises:
RuntimeError – If the find command cannot be found, or running it results in output to
stderr