folder flat without hidden files
This commit is contained in:
@@ -5,6 +5,7 @@ function help() {
|
|||||||
echo "Empty folders are removed"
|
echo "Empty folders are removed"
|
||||||
echo " -f to force action "
|
echo " -f to force action "
|
||||||
echo " -n to move files as is, i.e. not include path names in new name "
|
echo " -n to move files as is, i.e. not include path names in new name "
|
||||||
|
echo " -H include hidden files/folders "
|
||||||
echo " -p C Replace path separator / with character C "
|
echo " -p C Replace path separator / with character C "
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,33 +14,45 @@ function helpexit() {
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function finder() {
|
||||||
|
if [[ "$FILTER" -eq 0 ]]; then
|
||||||
|
find . -mindepth 2 -type f -path '*.*' -printf %P'\n'
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
if [[ "$FILTER" -eq 1 ]]; then
|
||||||
|
find . -mindepth 2 -not -path '*/\.*' -type f -printf %P'\n'
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function preview() {
|
function preview() {
|
||||||
echo ""
|
echo ""
|
||||||
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' | head ); do
|
for f in $( finder | head ); do
|
||||||
[[ "$NO_PATH" = "1" ]] && {
|
[[ "$NO_PATH" = "1" ]] && {
|
||||||
echo "$f => " .
|
echo "$f => " .
|
||||||
} || {
|
} || {
|
||||||
echo "$f =>" "${f//\//$SEP}"
|
echo "$f =>" "${f//\//$SEP}"
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
echo "..."
|
echo "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
function flat() {
|
function flat() {
|
||||||
[[ "$FORCE" = "0" ]] && INTERACT="-i"
|
[[ "$FORCE" = "0" ]] && INTERACT="-i"
|
||||||
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' ); do
|
for f in $( finder ); do
|
||||||
[[ "$NO_PATH" = "1" ]] && {
|
[[ "$NO_PATH" = "1" ]] && {
|
||||||
mv -v $INTERACT "$f" .
|
mv -v $INTERACT "$f" .
|
||||||
} || {
|
} || {
|
||||||
mv -v $INTERACT "$f" "${f//\//$SEP}"
|
mv -v $INTERACT "$f" "${f//\//$SEP}"
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
find . -depth -type d -empty -delete
|
find . -depth -type d -empty -delete
|
||||||
}
|
}
|
||||||
|
|
||||||
SEP="_"
|
SEP="_"
|
||||||
FORCE=0
|
FORCE=0
|
||||||
while getopts fhnp: opt
|
FILTER=1
|
||||||
|
while getopts fhHnp: opt
|
||||||
do case "$opt" in
|
do case "$opt" in
|
||||||
f)
|
f)
|
||||||
FORCE=1
|
FORCE=1
|
||||||
@@ -47,6 +60,9 @@ do case "$opt" in
|
|||||||
h)
|
h)
|
||||||
helpexit
|
helpexit
|
||||||
;;
|
;;
|
||||||
|
H)
|
||||||
|
FILTER=0
|
||||||
|
;;
|
||||||
n)
|
n)
|
||||||
NO_PATH=1
|
NO_PATH=1
|
||||||
;;
|
;;
|
||||||
@@ -60,6 +76,6 @@ IFS=$'\n'
|
|||||||
help
|
help
|
||||||
preview
|
preview
|
||||||
echo "Are you sure? Break with ctrl-c"
|
echo "Are you sure? Break with ctrl-c"
|
||||||
read i
|
read i
|
||||||
}
|
}
|
||||||
flat
|
flat
|
||||||
|
|||||||
Reference in New Issue
Block a user