## Using scandir import os directory = r'C:Usersadmin' for entry in os.scandir(directory): if (entry.path.endswith(".jpg") or entry.path.endswith(".png")) and entry.is_file(): print(entry.path)