-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdailydir
More file actions
executable file
·58 lines (52 loc) · 1.97 KB
/
dailydir
File metadata and controls
executable file
·58 lines (52 loc) · 1.97 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
#!/usr/bin/env bash
##############################################################################
#
# dailydir - copy files from memory card to disk into daily subfolders
#
# Copy ORF files from Olympus camera card to D: drive using WSL:
# 1. make mount point in WSL: sudo mkdir /mnt/e
# 2. mount the memory card in WSL: sudo mount -t drvfs E: /mnt/e
# 3. run this script to copy files into subfolders <DST>/<year>/<yyyy-mm-dd>
# 4. remove the memory card from WSL: sudo umount /mnt/e
#
# (c) 2020 E. Dronkert
# https://github.com/ednl
#
##############################################################################
SRC="/mnt/e/DCIM/101OLYMP" # location of original photo files
DST="/mnt/d/ewoud/Pictures/Olympus E520" # destination base dir
EXT=".ORF" # Olympus Raw Format files
[ ! -e "$SRC" ] || [ ! -d "$SRC" ] || [ ! -r "$SRC" ] && {
echo "Not accessible: $SRC" >&2
echo "Connect memory card: sudo mount -t drvfs E: /mnt/e" >&2
exit 1
}
[ ! -e "$DST" ] || [ ! -d "$DST" ] || [ ! -w "$DST" ] && {
echo "Not accessible: $DST" >&2
exit 2
}
N=$(find "$SRC" -maxdepth 1 -type f -name '*'"$EXT" | wc -l)
[ -z "$N" ] || [ "$N" -lt 1 ] && {
echo "No $EXT files found in $SRC" >&2
exit 3
}
echo "Files found: $N"
echo
for D1 in $(stat -c '%y' "$SRC/"*"$EXT" | cut -d' ' -f1 | sort | uniq)
do
D2=$(date -d "$D1 +1 day" +%Y-%m-%d) # the next day as boundary
Y=${D1%%-*} # the year as main subfolder
SUB="$DST/$Y/$D1" # destination base dir + sub-sub-folder
[ ! -e "$SUB" ] && mkdir -p "$SUB" # create subfolder if not exists
[ ! -e "$SUB" ] || [ ! -d "$SUB" ] || [ ! -w "$SUB" ] && {
echo "Not accessible: $SUB" >&2
exit 4
}
echo "Copying to $SUB" # the current day subfolder
find "$SRC" -maxdepth 1 -type f \
-name '*'"$EXT" \
-newermt "$D1" ! -newermt "$D2" \
-print -execdir cp -n -t "$SUB" {} +
echo
done
echo "Done. Disconnect memory card: sudo umount /mnt/e"