0

i have a folder with tons of subfolders containing png's. how can i step recursively through the subfolders and convert that files to pdf?
The pdf should have the name of the subfolder and be saved in the starting folder ... there are no folders in folders, no problem with double names expected. i'm beginner, tried other ideas, but terrible things happend ...

joe

muru
  • 197,895
  • 55
  • 485
  • 740
  • Also see: https://askubuntu.com/questions/1011550/how-can-i-convert-all-video-files-in-nested-folders-batch-conversion – muru Oct 02 '18 at 06:48
  • @muru how? ffmpeg does not convert to PDF. – Allan Bertelsen Oct 02 '18 at 06:57
  • 1
    @AllanBertelsen oh, copy-pastad'd. That was supposed to be https://askubuntu.com/questions/749882/ (with BMP/PNG replaced with PNG/PDF) – muru Oct 02 '18 at 07:02
  • @muru yes that's much better. Combined with the fact that convert also takes png to pdf as you mention. – Allan Bertelsen Oct 02 '18 at 07:07
  • no video ... simply open one subfolder, make convert command, next subfolder, convert ... until there are no more subfolders – Peppi Holland Oct 02 '18 at 07:08
  • @muru Not exact duplicate, plus title is misleading. In the opening line of that post OP stated "I have a directory on my machine with 100s of images in it" , so they have a flat directory actually, nothing recursive. This question here has non-flat directory tree. – Sergiy Kolodyazhnyy Oct 02 '18 at 07:16
  • @SergiyKolodyazhnyy yet OP there explicitly asks for recursive, and the answer has a recursive version. So what's the point of your objection? – muru Oct 02 '18 at 07:21

2 Answers2

1

A script like this would do the trick

#!/bin/bash
for D in `find . -mindepth 1 -type d`
do
    convert `ls -1v $D/*.png` $D.pdf
done
mosh442
  • 111
  • 2
  • 1
  • Do not parse ls command's output ever: https://mywiki.wooledge.org/ParsingLs 2) Do not use backticks in general 3) Either use glob or use find directly, don't combine them: https://dwheeler.com/essays/filenames-in-shell.html. Not going to downvote this answer, but this is bad quality over all
  • – Sergiy Kolodyazhnyy Oct 02 '18 at 07:09
  • Very interesting feedback. Thank you for your comments and the pointers. – mosh442 Oct 02 '18 at 07:14