-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_recording.sh
68 lines (56 loc) · 1.53 KB
/
sort_recording.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
#!/bin/bash
SEARCH="Audios"
DESTINY=$(date +%Y)
NAMES=("")
function main
{
searchDir=$1
parentToDir=$2
rootDir=$PWD
echo $rootDir
cd $rootDir/"$searchDir"
for file in $(ls -1)
do
date=$(echo $file | cut -f 1 -d '_')
time=$(echo $file | cut -f 2 -d '_' | cut -f 1 -d '-')
if date -d "$date" > /dev/null 2>&1; then
echo $file " not a valid file!"
continue #process next file
fi
dow=$(echo $(date -d "$date" +%u)) #day of week (1: monday - 7: sunday)
if [[ ${NAMES[$dow]+yes} == 'yes' ]]; then #valid name for given day of week in array
dir=${NAMES[$dow]}
else
if date -d "$date" > /dev/null 2>&1; then #valid date
day=$(echo $(date -d "$date" '+%A'))
if [ $time -lt 12 ]; then
shift='morning'
elif [ $time -lt 18 ]; then
shift='afternoon'
else
shift='evening'
fi
dir=$day"_"$shift #eg: Tuesday_evening
fi
fi
if [[ ${dir:-no} == 'no' ]]; then #no folder name set
echo "No folder name set!"
continue #process next file
fi
#destiny folder (files will be moved here)
if [ -n "$parentToDir" ]; then #if there is a parent destiny folder set
if [ ! -d $rootDir/"$parentToDir" ]; then #if the folder doesn't exist
mkdir $rootDir/"$parentToDir" #create it
fi
cd $rootDir/"$parentToDir" #change to parent destiny folder
fi
if [ ! -d "$dir" ]; then #if destiny folder doesn't exist
mkdir "$dir" #create it
fi
mv $rootDir/$searchDir/$file "$dir"
echo $rootDir/$searchDir/$file" => "$dir
cd
done
}
main ${1:-$SEARCH} ${2:-$SEARCH}
exit