I want to loop through files with extension ends with CR2, CR3, cr2, cr3 (contain cr in the extensions) only. Currently, I am using os.walk() but people recommend to use pathlib which I can do something like path.glob('*.jpg') but still I cannot specify the desired condition. Is there a better way to do this? for root, dirs, files in os.walk(cfg.RAWIMG_DIR): dirs.sort() for file in files: if dir > '10': path = Path(root) / file if 'cr' in path.suffix.lower(): Additionally, since there are too many files, I would to process portion by portion (Say 10 files at a time) during the loop. This is why I need the list of dir names as well. Continue reading...