I'm trying to figure out how to write a script to automate creating .cbz files from images in folders on OSX.
My directory tree will look like this:
/toplevel/
cbz/
comics/
Comic1/
comic1file1.jpg
comic1file2.gif
comic1file3.png
Comic2/
comic2file1.jpg
comic2file2.gif
Publisher/
Comic3/
comic3file1.jpg
comic3file2.gif
comic3file3.png
Comic4/
comic4file1.jpg
comic4file2.gif
And what I'd like to do is run a script that will find any folder containing actual files rather than subfolders and zip it, rename it from .zip to .cbz and move the .cbz file to the /cbz folder on the toplevel. Any folder that contains subfolders should not contain any files, so that might be helpful. Also I don't expect there to ever be subfolders deeper than what is shown in the example above.
Where I'm at: This snippet will look through a folder and create the .cbz-files for each subfolder.
for dir in `ls`; do zip $dir $dir/*; mv $dir*zip $dir.cbz; done
I've also found some snippets that will do something similar to every subfolder below the selected folder, but I've had varying results and would be very interested to learn the best way of performing an operation only on folders. Also I have NO clue as to how I should check whether a given folder contains subfolders or files. (I guess ideally I should include checks to see if there are both, but for my current scenario that shouldn't ever be the case.) Any ideas?
ls
; do zip $dir $dir/*; mv $dir*zip $dir.cbz; done´ and I've managed to make it look for subfolders. My biggest hurdle right now is determining if a folder contains subfolders or files.