get_files
-
Description
Get all files in the specified folder. Note that the
suffix
here is case-insensitive, but you must remember to include the.
. Many times, not finding files is due to this issue. -
Parameters
- folder (
folder: Union[str, Path]
): The specified folder. - suffix (
suffix: Union[str, List[str], Tuple[str]]
): The suffix(es) of the files to retrieve. For example: ['.jpg', '.png']. Defaults to None, indicating retrieving all files in the folder. - recursive (
bool
): Whether to include files in subfolders. Defaults to True. - return_pathlib (
bool
): Whether to return Path objects. Defaults to True. - sort_path (
bool
): Whether to return a list of paths sorted in natural order. Defaults to True. - ignore_letter_case (
bool
): Whether to include suffixes with different cases. Defaults to True.
- folder (
-
Returns
- List[Path]: A list of file paths.
-
Example
import docsaidkit as D
folder = '/path/to/your/folder'
files = D.get_files(folder, suffix=['.jpg', '.png'])
print(files)
# >>> ['/path/to/your/folder/1.jpg', '/path/to/your/folder/2.png']