Last active
August 29, 2015 14:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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