-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_pics_to_folders.sh
executable file
·111 lines (96 loc) · 2.83 KB
/
move_pics_to_folders.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# $Id: $
# Author(s) : Daniel Kriesten
# Email : [email protected]
# Creation Date : Fr 25 Sep 2009 11:13:45 #u
function createFilelist ()
{
local SORTLIST=""
local i
FILELIST=""
SORTLIST=$(gfind "${BASEDIR}" -iname "${1}" | xargs basename | sort -u)
for i in ${SORTLIST}; do
FILELIST="${FILELIST} $(gfind "${BASEDIR}" -name ${i})"
done
}
#function createFolder ()
#{
# for j in $(gfind ${BASEDIR} -maxdepth 1 -type d); do
# i="$(basename ${j})"
# i="$(basename${1})"
# echo $i
# YEAR="$(echo ${i} | cut -d '-' -f 1 | sed 's/[ \t]*//;s/[ \t]*$//')"
# MONTH="$(echo ${i} | cut -d '-' -f 2 | sed 's/[ \t]*//;s/[ \t]*$//')"
# EVENT="$(echo ${i} | cut -d '-' -f 4 | sed 's/[ \t]*//;s/[ \t]*$//')"
# echo ${YEAR}/${YEAR}_${MONTH}_${EVENT}
# done
#}
function getDirNameByExif ()
{
TMP="$(exiv2 "${1}" | grep Zeitstempel)"
TMP="$(echo ${TMP} | cut -d ' ' -f 4 | sed 's/^[ \t]*//;s/[ \t]*$//')"
YEAR="$(echo ${TMP} | cut -d ':' -f 1 | sed 's/^[ \t]*//;s/[ \t]*$//')"
MONTH="$(echo ${TMP} | cut -d ':' -f 2 | sed 's/^[ \t]*//;s/[ \t]*$//')"
DAY="$(echo ${TMP} | cut -d ':' -f 3 | sed 's/^[ \t]*//;s/[ \t]*$//')"
#DIRNAME=${TARGETBASE}/${YEAR}/${YEAR}_${MONTH}
DIRNAME=${TARGETBASE}/${YEAR}/${YEAR}-${MONTH}-${DAY}
}
function getDirNameByEvent ()
{
li="$(basename ${1})"
YEAR="$(echo ${li} | cut -d '-' -f 1 | sed 's/[ \t]*//;s/[ \t]*$//')"
MONTH="$(echo ${li} | cut -d '-' -f 2 | sed 's/[ \t]*//;s/[ \t]*$//')"
EVENT="$(echo ${li} | cut -d '-' -f 4 | sed 's/[ \t]*//;s/[ \t]*$//')"
if [ ! -z ${EVENT} ]; then
EVENT=_"$EVENT"
fi
echo \"$YEAR\" \"$MONTH\" \"$EVENT\"
DIRNAME=${TARGETBASE}/${YEAR}/${YEAR}_${MONTH}${EVENT}
}
function sortToFolder ()
{
local i
for i in ${FILELIST}; do
#getDirNameByEvent $(dirname ${i})
getDirNameByExif ${i}
FILE="$(basename ${i})"
mkdir -p ${DIRNAME}
# Durchsuche Zielverzeichnis nach Duplikaten
# und zähle diese mit.
#if [ -e "${DIRNAME}/${FILE}" ]; then
#SUBCNT=1
#while ( [ -e "${DIRNAME}/${FILE}_${SUBCNT}" ] ); do
#let SUBCNT=SUBCNT+1
#done
#SUBCNT="_${SUBCNT}"
#fi
# Neu: Ignoriere Duplikate!
if [[ -e "${DIRNAME}/${FILE}" ]]; then
echo "** \"${DIRNAME}/${FILE}\" existiert! **"
else
for x in ${i%.*}.*; do
mv -iv "${x}" "${DIRNAME}/$(basename ${x})${SUBCNT}"
done
fi
#echo mv -iv "${i}" "${DIRNAME}/${FILE}${SUBCNT}"
#cp -iv "${i}" "${DIRNAME}/${FILE}${SUBCNT}"
#jhead -nf'%Y%m%d-%f' "${DIRNAME}/${FILE}${SUBCNT}"
SUBCNT=""
done
}
BASEDIR=${1:-.}
pushd ${BASEDIR}
BASEDIR=${PWD}
popd
echo "BASEDIR=${BASEDIR}"
TARGETBASE=${2:-./FotosNeu}
pushd ${TARGETBASE}
TARGETBASE=${PWD}
popd
echo "TARGETBASE=${TARGETBASE}"
BASEEXT=${3:-jpg}
echo "BASEEXT=${BASEEXT}"
createFilelist "*.${BASEEXT}"
sortToFolder
# vim: ts=2:sw=2:tw=0:fileformat=unix
# vim: comments& comments+=b\:# formatoptions& formatoptions+=or