File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ node_modules
66package.json
77photos /
88archives /
9+ album-photos /renamed /
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # rename files for photo album app
4+ # Original filenames expected to be formatted as name.number.jpg.
5+ #
6+ for file in * .jpg * .png * .jpeg; do # Add other extensions as needed
7+ if [ -f " $file " ]; then
8+ dimensions=$( identify -format " %wx%h" " $file " )
9+ # echo "${dimensions}"
10+ width=$( identify -format " %w" " $file " )
11+ # echo "${width}"
12+ delimiter=' .'
13+ # Temporarily set IFS to the delimiter and use read to populate an array
14+ IFS=" $delimiter " read -ra my_array <<< " $file"
15+ # echo "my_array: ${my_array[@]}"
16+ array_len=" ${# my_array[@]} "
17+
18+ if [[ $array_len -lt 3 ]]; then
19+ echo " error, filename is too short: ${my_array[@]} "
20+
21+ else
22+ new_filename=" ${my_array[0]} .${my_array[1]} .${dimensions} .${width} w.${my_array[2]} "
23+ echo " ${new_filename} "
24+ mv " $file " " renamed/$new_filename "
25+ fi
26+ fi
27+ done
You can’t perform that action at this time.
0 commit comments