-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwxdir
More file actions
executable file
·83 lines (78 loc) · 1.99 KB
/
wxdir
File metadata and controls
executable file
·83 lines (78 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
#####################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : Mac OS X
# Requires : bash
# Location : ~/bin/
# Name : wxdir
# Version : 1.0.1
# Date : 2017-07-19
# Purpose : Correct the impractical daily subfolder names
# of Sony sync tool from DD-MM-YY to YYYYMMDD.
# Parameters : none
# Settings : WXDIR = main photo folder on disk
# CENTURY = which century to use for full date
#####################################################################
WXDIR=~/Pictures/Camera\ Sony\ WX220
CENTURY=20
echo -n "Renaming synced folders ... "
N=0
OK=0
ERR=0
find "$WXDIR" \
-mindepth 1 -maxdepth 1 \
-type d \
-name [0-9][0-9]-[0-9][0-9]-[0-9][0-9] | \
while IFS= read -r OLD; do
if [ -d "$OLD" ]; then
(( ++N ))
DAY="$CENTURY${OLD:(-2)}${OLD:(-5):2}${OLD:(-8):2}"
NEW="$WXDIR/$DAY"
TRY=0
BASE="$NEW"
while [ -e "$NEW" -a $TRY -lt 9 ]; do
(( ++TRY ))
NEW="$BASE-$TRY"
done
if [ ! -e "$NEW" ]; then
if (( TRY > 0 )); then
echo -n "\n Warning: duplicate folder name, using '$NEW' " 1>&2
fi
mv -f "$OLD" "$NEW" && (( ++OK ))
touch -t "${DAY}0000.00" "$NEW"
else
echo -n "\n Failed: unable to rename '$OLD' " 1>&2
(( ++ERR ))
fi
fi
done
echo "done."
echo " Folders found as DD-MM-YY: $N"
echo " Renamed to YYYYMMDD: $OK"
(( ERR > 0 )) && echo " Unable to rename: $ERR"
echo -n "Checking folder timestamps ... "
N=0
M=0
OK=0
find "$WXDIR" \
-mindepth 1 -maxdepth 1 \
-type d \
-name [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | \
while IFS= read -r DIR; do
if [ -d "$DIR" ]; then
(( ++N ))
T1="${DIR:(-8)}"
T2=$(stat -q -f '%Sm' -t '%Y%m%d' "$DIR")
if [ "$T1" != "$T2" ]; then
(( ++M ))
touch -t "${T1}0000.00" "$DIR" && (( ++OK ))
fi
fi
done
echo "done."
(( N > 0 )) && echo " Folders found: $N"
(( M > 0 )) && echo " Wrong timestamp: $M"
(( OK > 0 )) && echo " Corrected timestamp: $OK"
open "$WXDIR"
exit 0