Skip to content

Commit 0065fd0

Browse files
committed
added script to rename files
1 parent d3b0650 commit 0065fd0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules
66
package.json
77
photos/
88
archives/
9+
album-photos/renamed/

album-photos/script.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

0 commit comments

Comments
 (0)