-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathordering.sh
More file actions
executable file
·100 lines (74 loc) · 1.64 KB
/
ordering.sh
File metadata and controls
executable file
·100 lines (74 loc) · 1.64 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
function doTheSort {
echo -ne "\nSorting files, please wait... "
for FILE in `ls $SOURCE_FOLDER`
do
full_file_path=${SOURCE_FOLDER}/${FILE}
date_folder=`stat -c %y ${full_file_path} | cut -d' ' -f 1`
file_year=`echo $date_folder | cut -d'-' -f 1`
file_month=`echo $date_folder | cut -d'-' -f 2`
file_day=`echo $date_folder | cut -d'-' -f 3`
#echo $date_folder
#echo "$file_year,$file_month,$file_day"
full_dest=${DEST_BASE_FOLDER}/${file_year}/${file_month}/${file_day}/
if [[ ! -d "${full_dest}" ]]
then
#echo "Creating folder..."
mkdir -p ${full_dest}
fi
cp --preserve=timestamps ${full_file_path} ${full_dest}/
if [ $? -eq 0 ]
then
rm ${full_file_path}
fi
done
echo -ne "OK!\n"
}
function usage {
echo -e "\nUsage:"
echo -e "\t./ordering.sh --source,-s <source_folder> --dest,-d <destination_folder> [--version,-v]\n"
exit 1
}
function readParams {
if [ $# -eq 0 ];
then
usage
exit -1
fi
PARSED_OPTIONS=$(getopt -n "$0" -o s:d:h --long "source:,dest:,help" -- "$@")
if [ $? -ne 0 ];
then
usage
fi
eval set -- "$PARSED_OPTIONS"
while true;
do
case "$1" in
-h|--help)
usage
;;
-s|--source)
if [ -n "$2" ]
then
SOURCE_FOLDER=$2
fi
echo "SOURCE_FOLDER=$SOURCE_FOLDER"
shift 2;;
-d|--dest)
if [ -n "$2" ]
then
DEST_BASE_FOLDER=$2
fi
echo "DEST_BASE_FOLDER=$DEST_BASE_FOLDER"
shift 2;;
--)
shift
break;;
esac
done
}
### MAIN ###
echo -e "Sorting script\n"
readParams $@
doTheSort
### EOF ###