55
66
77def locate_files (inputs : Union [str , List [str ]], input_lists : Union [str , List [str ]] = None ,
8- fail_if_empty : bool = False ) -> List [str ]:
8+ fail_if_empty : bool = False , default_glob : str = None ) -> List [str ]:
99 """
1010 Locates all the files from the specified inputs, which may contain globs.
1111 glob results get sorted to ensure the same file order each time.
12+ If default_glob is not None and the inputs are pointing to directories, then default_glob
13+ gets appended.
1214
1315 :param inputs: the input path(s) with optional globs
1416 :type inputs: str or list
1517 :param input_lists: text file(s) that list the actual input files to use
1618 :type input_lists: str or list
1719 :param fail_if_empty: whether to throw an exception if no files were located
1820 :type fail_if_empty: bool
21+ :param default_glob: the default glob to use, ignored if None
22+ :type default_glob: str
1923 :return: the expanded list of files
2024 :rtype: list
2125 """
@@ -30,6 +34,11 @@ def locate_files(inputs: Union[str, List[str]], input_lists: Union[str, List[str
3034 else :
3135 raise Exception ("Invalid inputs, must be string(s)!" )
3236
37+ if default_glob is not None :
38+ for i , inp in enumerate (inputs ):
39+ if os .path .isdir (inp ):
40+ inputs [i ] = os .path .join (inp , default_glob )
41+
3342 if input_lists is not None :
3443 if isinstance (input_lists , str ):
3544 input_lists = [input_lists ]
0 commit comments