File: rm-empty-dirs

package info (click to toggle)
musescore 2.0.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 202,532 kB
  • ctags: 58,769
  • sloc: cpp: 257,595; xml: 172,226; ansic: 139,931; python: 6,565; sh: 6,383; perl: 423; makefile: 290; awk: 142; pascal: 67; sed: 3
file content (26 lines) | stat: -rwxr-xr-x 947 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

# Use this script to tidy up a directory tree after deleting files (e.g.
# when uninstalling MuseScore). The script takes as argument a path (or
# a space-delimited list of paths) to recently deleted files:
#   e.g. "/usr/local/share/mscore-dev-2.1/manual/plugins/harmony.html"
# If the file still exists nothing happens. If it's parent directory is
# empty then that is deleted. The parent's parent is deleted if it is
# now empty, and so on until all empty parents in the path are deleted.

numempty=0

for filepath in "$@" ; do
  #echo "File: $filepath"
  dirpath=$(dirname "$filepath")
  while true ; do
    #echo "Directory: $dirpath"
    rmdir "$dirpath" 2>/dev/null || continue 2
    # Note: this is safe because `rmdir` only removes empty directories.
    #echo "Removed empty directory: $dirpath"
    numempty=$(($numempty+1))
    dirpath=$(dirname "$dirpath")
  done
done

echo "$0: $numempty empty directories were removed."