Asserting:
0) no directory names contain spaces or other IFS b0rkage,
1) subdirectories are all in one root (here: /path/to/directories) and
2) at the same level and you
2) mod your function a bit (use 'find' instead of "for i in"),
you could:
Code:
myRename() { c=0; for i in *.pdf; do test -f "$i" && mv "$i" $(printf "${PWD##*/}%03i.pdf" $c) && ((c+=1)); done; }
cd /path/to/directories; find . -type d -maxdepth 1 | while read SUBDIR; do
cd "${SUBDIR}" && myRename && cd ..
done