I'm using the following code (from this answer) to convert all CPP files in the current directory to a file named code.pdf and it works well:
find . -name "*.cpp" -print0 | xargs -0 enscript -Ecpp -MLetter -fCourier8 -o - | ps2pdf - code.pdf
I would like to improve this script to:
Make it a .sh file that can take an argument specifying the extension instead of having it hardcoded to CPP;
Have it run recursively, visiting all subdirectories of the current directory;
For each subdirectory encountered, convert all files of the specified extension to a single PDF that is named $NameOfDirectory$.PDF and is placed in that subdirectory;