Skip to content

Instantly share code, notes, and snippets.

@simonthompson99
Last active January 15, 2021 12:46
Show Gist options
  • Save simonthompson99/d8bb8505f4ddd91d8fcd31fb5e683573 to your computer and use it in GitHub Desktop.
Save simonthompson99/d8bb8505f4ddd91d8fcd31fb5e683573 to your computer and use it in GitHub Desktop.
[Collapse png tree] Convert folder of pngs to a pdf taking folder name as filename #bash #imagemagick #file_operations
# Takes a folder tree of pngs and converts them to pdf per folder. e.g.
# |- 1
# | |- 1_1.png
# | |- 1-2.png
# |- 2
# | |- 2_1.png
# | |- 2_2.png
#
# will create two pdfs called 1.pdf and 2.pdf in the directory of script.
for file in `find . -name "*.png" -exec dirname {} \; | sort | uniq`
do
base="$(basename $file)"
echo "$base"
files="$(find $file -type f -name "*.png" | sort)"
echo "$files"
convert $files "$base.pdf"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment