Add file_utils/prefixsubdirs.sh
parent
79157b7a4f
commit
b08187c113
@ -0,0 +1 @@
|
||||
../file_utils/prefixsubdirs.sh
|
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# prefixsubdirs.sh, Copyright © 2018 Matteo Cypriani
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
#
|
||||
# For each directory provided on the command-line, this script prefixes its
|
||||
# subdirectorie(s) with its name and a separator (" ; " by default).
|
||||
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
SEPARATOR=' ; '
|
||||
MVOPTS='-v'
|
||||
|
||||
prefix_subdirs()
|
||||
(
|
||||
dir="$1"
|
||||
cd "$dir"
|
||||
|
||||
files="$(echo -- *)"
|
||||
[ "$files" = '*' ] && return 0
|
||||
|
||||
for file in * ; do
|
||||
[ -d "$file" ] || continue
|
||||
mv $MVOPTS "$file" "${dir}${SEPARATOR}${file}"
|
||||
done
|
||||
)
|
||||
|
||||
if [ $# -lt 1 ] ; then
|
||||
echo "Usage: $(basename "$0") DIRECTORY [DIRECTORY [...]]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while [ -n "$1" ] ; do
|
||||
dir=$1
|
||||
shift
|
||||
|
||||
if [ ! -d "$dir" ] ; then
|
||||
printf 'Warning! "%s" is not a directory: ignoring.\n' "$dir" >&2
|
||||
continue
|
||||
fi
|
||||
|
||||
printf 'Entering "%s" ...\n' "$dir"
|
||||
prefix_subdirs "$dir"
|
||||
done
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Reference in New Issue