swectral.search_file#

swectral.search_file(directory_path, search_pattern, end_with='', exclude_list=None)[source]#

Search and list file paths in a directory.

Parameters:
pathstr

Directory path to search.

search_patternstr

Pattern to search. Wildcards “*” / “[]” / “?” / “[!]” are supported.

end_withstr

Filter file names ending with this pattern, extension is included. Default is empty string, which uses name extension when exists.

exclude_listlist of str

Filter file names that contains any strings in the exclude_list.

Returns:
list[str]

A list of file paths that match the search criteria.

Return type:

list[str]

Examples

>>> search_file("/some_dir", "*abc.tif")
>>> search_file("/some_dir", "abc?.tif")
>>> search_file("/some_dir", "abc[123].tif")
>>> search_file("/some_dir", "abc*", end_with=".tif")
>>> search_file("/some_dir", "abc*", end_with=".tif", exclude_list=["mask", "test"])