reorganization, and output filename for SimpleWeb
This commit is contained in:
64
files/FolderFlat
Executable file
64
files/FolderFlat
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/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 "
|
||||
echo " -n to move files as is, i.e. not include path names in new name "
|
||||
echo " -p C Replace path separator / with character C "
|
||||
}
|
||||
|
||||
function helpexit() {
|
||||
help
|
||||
exit
|
||||
}
|
||||
|
||||
function preview() {
|
||||
echo ""
|
||||
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' | head ); do
|
||||
[[ "$NO_PATH" = "1" ]] && {
|
||||
echo "$f => " .
|
||||
} || {
|
||||
echo "$f =>" "${f//\//$SEP}"
|
||||
}
|
||||
done
|
||||
echo "..."
|
||||
}
|
||||
|
||||
function flat() {
|
||||
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' ); do
|
||||
[[ "$NO_PATH" = "1" ]] && {
|
||||
mv -iv "$f" .
|
||||
} || {
|
||||
mv -iv "$f" "${f//\//$SEP}"
|
||||
}
|
||||
done
|
||||
find . -depth -type d -empty -delete
|
||||
}
|
||||
|
||||
SEP="_"
|
||||
FORCE=0
|
||||
while getopts fhnp: opt
|
||||
do case "$opt" in
|
||||
f)
|
||||
FORCE=1
|
||||
;;
|
||||
h)
|
||||
helpexit
|
||||
;;
|
||||
n)
|
||||
NO_PATH=1
|
||||
;;
|
||||
p)
|
||||
SEP=$OPTARG
|
||||
;;
|
||||
esac
|
||||
done
|
||||
IFS=$'\n'
|
||||
[[ "$FORCE" = "0" ]] && {
|
||||
help
|
||||
preview
|
||||
echo "Are you sure? Break with ctrl-c"
|
||||
read i
|
||||
}
|
||||
flat
|
||||
Reference in New Issue
Block a user