Skip to content

Instantly share code, notes, and snippets.

@cyberbikepunk
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberbikepunk/d630eab3d9c6c7bd85ba to your computer and use it in GitHub Desktop.
Save cyberbikepunk/d630eab3d9c6c7bd85ba to your computer and use it in GitHub Desktop.
Recursively look for images inside a source folder and create flat symlinks inside a destination folder.
#! /usr/bin/python3
"""
Recursively look for images inside a source folder
and create flat symlinks inside a destination folder.
"""
from argparse import ArgumentParser
from os import walk
from pathlib import Path
DIR = 0
FILES = 2
VALID_EXTENTIONS = {'.jpg',
'.jpeg',
'.bmp',
'.gif',
'.tiff',
'.exif',
'.rif'}
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('source')
parser.add_argument('destination')
args = parser.parse_args()
tree = walk(args.source)
for node in tree:
for file in node[FILES]:
if Path(file).suffix in VALID_EXTENTIONS:
image = Path(node[DIR], file)
link = Path(args.destination, image.name)
if not link.exists():
link.symlink_to(image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment