setup_numerical_names.sh 632 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. i=2
  3. # set $i to the the highest numbered folder + 1
  4. for h in $(find . -mindepth 1 -maxdepth 1 -type d -name "[0-9][0-9]" -o -name "[0-9][0-9][0-9]" | awk -F'/' '{print $NF}'); do
  5. [ $i -le $h ] && i=$(expr $h + 1)
  6. done
  7. SAVEIFS=$IFS
  8. IFS=$(echo -en "\n\b")
  9. # if using a menu that doesnt sort, add sorting to the output of the find command below
  10. for n in $(find . -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | egrep -v '[0-9][0-9]$|[0-9][0-9][0-9]$' | sort); do
  11. echo "ORIGINAL_DIRECTORY_NAME=\"$n\"" > "./$n/ofn.txt"
  12. export p="$(printf "%02d\n" $i)"
  13. mv -v "$n" $p
  14. let "i+=1"
  15. done
  16. IFS=$SAVEIFS