| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # Use this script to tidy up a directory tree after deleting files (e.g. |
| 4 | # when uninstalling MuseScore). The script takes as argument a path (or |
| 5 | # a space-delimited list of paths) to recently deleted files: |
| 6 | # e.g. "/usr/local/share/mscore-dev-2.1/manual/plugins/harmony.html" |
| 7 | # If the file still exists nothing happens. If it's parent directory is |
| 8 | # empty then that is deleted. The parent's parent is deleted if it is |
| 9 | # now empty, and so on until all empty parents in the path are deleted. |
| 10 | |
| 11 | numempty=0 |
| 12 | |
| 13 | for filepath in "$@" ; do |
| 14 | #echo "File: $filepath" |
| 15 | dirpath=$(dirnamescip-shell system . . dirname. "$filepath") |
| 16 | while truescip-shell system . . true. ; do |
| 17 | #echo "Directory: $dirpath" |
| 18 | rmdirscip-shell system . . rmdir. "$dirpath" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || continue 2 |
| 19 | # Note: this is safe because `rmdir` only removes empty directories. |
| 20 | #echo "Removed empty directory: $dirpath" |
| 21 | numempty=$(($numempty+1)) |
| 22 | dirpath=$(dirnamescip-shell system . . dirname. "$dirpath") |
| 23 | done |
| 24 | done |
| 25 | |
| 26 | echoscip-shell system . . echo. "$0: $numempty empty directories were removed." |