62 lines
1.2 KiB
Bash
62 lines
1.2 KiB
Bash
# Group files by extension.
|
|
# Usage: group_ext [FILES]
|
|
function group_ext() {
|
|
local IFS=$'\n'
|
|
local targets=(${@})
|
|
[[ "${targets}" = "" ]] && targets=($(_ls_file))
|
|
|
|
process() {
|
|
local ext=${target##*.}
|
|
[[ -d "${target}" ]] && { _iterate_skip "Is a directory."; return 0; }
|
|
[[ "${ext}" = "${target}" ]] && { _iterate_skip "No extension."; return 0; }
|
|
|
|
mkdir ${ext} 2> /dev/null
|
|
|
|
mv -- ${target} ./${ext}/${target}
|
|
}
|
|
|
|
_iterate_targets process ${targets[@]}
|
|
}
|
|
|
|
# Group files and dirs by year.
|
|
# Usage: group_year [FILES]
|
|
function group_year() {
|
|
local IFS=$'\n'
|
|
local targets=(${@})
|
|
[[ "${targets}" = "" ]] && targets=($(ls))
|
|
|
|
process() {
|
|
local year=$(stat --format=%y ${target})
|
|
year=${year%%-*}
|
|
|
|
mkdir ${year} 2> /dev/null
|
|
|
|
mv -- ${target} ./${year}/${target}
|
|
}
|
|
|
|
_iterate_targets process ${targets[@]}
|
|
}
|
|
|
|
# Copy files from current year to the named dir.
|
|
function group_year_current() {
|
|
local IFS=$'\n'
|
|
local targets=(${@})
|
|
[[ "${targets}" = "" ]] && targets=($(ls))
|
|
|
|
local today="$(date +%Y)"
|
|
mkdir ${today} 2> /dev/null
|
|
|
|
process() {
|
|
local year=$(stat --format=%y ${target})
|
|
year=${year%%-*}
|
|
|
|
if [[ "${year}" = "${today}" ]]; then
|
|
rcp -- ${target} ./${today}/
|
|
else
|
|
_iterate_skip
|
|
fi
|
|
}
|
|
|
|
_iterate_targets process ${targets[@]}
|
|
}
|