Skip to content

Instantly share code, notes, and snippets.

@blurymind
Last active June 13, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blurymind/d95d10c6e02544e9fea30f6aca11501c to your computer and use it in GitHub Desktop.
Save blurymind/d95d10c6e02544e9fea30f6aca11501c to your computer and use it in GitHub Desktop.
moveFilesOutOfFolders.sh
#!/bin/sh
# fix for folders/files with spaces in them (ln13)
OLDIFS=$IFS
IFS=$'\n'
# thunar folder custom action /home/fox/INSTALL/deleteSmallSizeSubFolders.sh %F
# %F is full path to all selected folders
for var in "$@"
do
# move files out
find "$var" -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 >= 50' | cut -f 2- | xclip -sel clip
for folder in $(xclip -selection c -o)
do
find $folder -mindepth 1 -maxdepth 1 -type f -exec du -ks {} + | awk '$1 >= 50' | cut -f 2- | xclip -sel clip
for file in $(xclip -selection c -o)
do
zenity --question --title="Confirm" --text="Move this file to parent folder?:\n$file\nto\n$var"
case $? in
0)
mv $file $var
# rm -r "$j"
zenity --notification --text "Moved:\n$file\n to parent folder:\n$var"
;;
1)
#cancel
#;;
esac
done
done
#cleanup
find $var -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50' | cut -f 2- | xclip -sel clip
for j in $(xclip -selection c -o)
do
zenity --question --title="Confirm" --text="This folder is likely empty:\n $j\n\nDelete it?"
case $? in
0)
rm -r "$j"
zenity --notification --text "Deleted\n$j"
;;
1)
#cancel
;;
esac
done
# end cleanup
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment