image: Use os.scandir to find images.

This commit is contained in:
Dylan Araps 2017-06-27 21:07:19 +10:00
parent bb81f1a43d
commit b5c27de8b5

View File

@ -22,8 +22,8 @@ def random_img(img_dir):
# Add all images to a list excluding the current wallpaper. # Add all images to a list excluding the current wallpaper.
file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif") file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
images = [img for img in os.listdir(img_dir) images = [img for img in os.scandir(img_dir)
if img.endswith(file_types) and img != current_wall] if img.name.endswith(file_types) and img.name != current_wall]
return pathlib.Path(img_dir / random.choice(images)) return pathlib.Path(img_dir / random.choice(images))