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;
First, if I understand it correctly, this requirement:
is unwise. If that means, say,
a/b/c/*.cppgets enscripted to./c.pdf, then you're screwed if you also havea/d/x/c/*.cpp, since both directories' contents map to the same PDF. It also means that*.cpp(i.e. CPP files in the current dir) gets enscripted to a file named./..pdf.Something like this, which names the PDF according to the desired extension and places it in each subdirectory alongside its source files, doesn't have those problems: