Nautilus – Empty Dir Script

“What does this do?” It sucks in air!

  • Tries to move all files out of the marked folder
  • Tries to remove the (now empty) dir
  • [If something cannot be done (no sufficent rights, file already exists, directory could not be emptied) it won’t (should not) do it]

Its released under the GPLv2. Use it at your own risk. There should be no dataloss (except the marked directory itself) because all used commands take care of remaining (already existing) files.

#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "nb")

FILES=${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}

for FILE in ${FILES} ; do
    if [ -d ${FILE} ]; then
             cd "${FILE}"
             mv -n * ..
             cd ..
             rmdir "${FILE}"
    fi
done

IFS=$SAVEIFS

Have fun!

FAQ nautilus scripts (http://g-scripts.sourceforge.net/faq.php)