Update lsn.
[scripts.git] / mvdatedir.sh
1 #!/bin/bash
2
3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify  #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation.                         #
7 #                                                                       #
8 # This program is distributed in the hope that it will be useful, but   #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
11 # General Public License for more details.                              #
12 #                                                                       #
13 # You should have received a copy of the GNU General Public License     #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
15 #                                                                       #
16 # Written by and Copyright (C) Francois Fleuret                         #
17 # Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
18 #########################################################################
19
20 # This script moves all the files specified as argument to directories
21 # of the form YEAR/MONTH, according to the files modification
22 # dates. The directories are created if necessary.
23
24 set -e
25
26 while [[ "$1" ]]; do
27     if [[ -f "$1" ]]; then
28         dir=$(date -r "$1" +%Y/%b)
29         mkdir -p ${dir}
30         echo "$1 -> ${dir}"
31         mv "$1" ${dir}
32     else
33         echo "Ignore: $1 is not a regular file."
34     fi
35     shift
36 done