new tools for folder manipulation
This commit is contained in:
28
FolderFlat
Executable file
28
FolderFlat
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/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 " -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user