


Each $dir is searched for files ( -type f) that are actually in that directory and not in sub directories ( -mindepth 1 -maxdepth 1). The results of that find are piped to the while loop which processes each of them saved in the variable $dir. This ensures that find will not return toplevel/comics itself as a result. The 1st find command searches toplevel/comics/ for directories ( type -d) that are at least one level below ( -mindepth 1) the path given (subdirectories). & zip toplevel/cbz/"$(basename $dir)".cbd "$dir"/* Num=$(find "$dir" -mindepth 1 -maxdepth 1 -type f | wc -l ) Try this: find toplevel/comics/ -mindepth 1 -type d | Also, you can give zip an arbitrary name for the archive it will create so you don't need to move the 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.)įirst of all, never parse the output of ls. Also I have NO clue as to how I should check whether a given folder contains subfolders or files. 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. for dir in `ls` do zip $dir $dir/* mv $dir*zip $dir.cbz done Where I'm at: This snippet will look through a folder and create the. Also I don't expect there to ever be subfolders deeper than what is shown in the example above. Any folder that contains subfolders should not contain any files, so that might be helpful. cbz file to the /cbz folder on the toplevel. My directory tree will look like this: /toplevel/Īnd 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. I'm trying to figure out how to write a script to automate creating.
