Files
q-tools/folderFlatten
2015-04-23 09:55:21 +03:00

29 lines
573 B
Bash
Executable File

#!/bin/bash
function help() {
echo "Flatten the directory structure from the current folder downwards"
echo "Files in subfolders will be renamed / -> _"
echo "Empty folders are removed"
echo -- " add -f to force action "
}
function helpexit() {
help
exit
}
[[ -z "$1" ]] && {
help
echo "Are you sure? Break with ctrl-c"
read i
}
[[ "$1" = "-h" ]] && helpexit
IFS=$'\n'
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' );
do mv -iv "$f" "$( echo $f | sed s,[/],_,g )"
done
find . -depth -type d -empty -delete