diff options
author | Karl Berry <karl@freefriends.org> | 2005-12-27 23:56:17 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2005-12-27 23:56:17 +0000 |
commit | 577983747d8680b8defbfdd03a9d50bad6fd54b7 (patch) | |
tree | 16b160f53c6c4c309c07db2c5b095d3abb16f69a /Build/cdbuild/zap-empty-dirs | |
parent | 07fed0169bae91dfb5616f9d19e7969727e19d4d (diff) |
initial Build
git-svn-id: svn://tug.org/texlive/trunk@4 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/cdbuild/zap-empty-dirs')
-rwxr-xr-x | Build/cdbuild/zap-empty-dirs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Build/cdbuild/zap-empty-dirs b/Build/cdbuild/zap-empty-dirs new file mode 100755 index 00000000000..b34ca0708c5 --- /dev/null +++ b/Build/cdbuild/zap-empty-dirs @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +# Usage: $0 [-debug] [-noaction] dir-name [regexp] + +# checks whether only files matching regexp are contained in +# dir-name and removes the directory if this is the case. +# -debug prints out what it does +# -noaction suppresses the deletion + +$debug = 0 unless $debug; +$noaction = 0 unless $noaction; + +sub usage { + print STDERR "Usage: $0 [-debug] [-noaction] dir-name [regexp]\n"; +} + + +if ($#ARGV >= 0) { + $dir_name = shift; +} else { + &usage; + exit 1; +} + +if ($#ARGV < 0) { + $regexp = "^(\\.zipped|\\.cache|\\.cache\\+|00Contents|00Description)\$"; +} elsif ($#ARGV == 0) { + $regexp = shift; +} else { + &usage; + exit 1; +} + + +opendir(DIR,$dir_name) || die "Cannot open directory `$dir_name'. Reason: $!"; + +@all_files = grep(! /^\.\.?$/,readdir(DIR)); # exclude . and .. + +closedir(DIR); + +@files = grep(! /$regexp/,@all_files); + +if ($#files < 0) { + print "Empty directory: $dir_name\n"; + &deldir; +} + +exit 0; + +sub deldir { + +# system "ls -lA $dir_name"; +# return; + + foreach $file (@all_files) { + $debug && print "unlink($dir_name/$file)\n"; + $noaction || + unlink("$dir_name/$file") || + die "Could not unlink file `$dir_name/$file'! Reason: $!\n"; + } + + $debug && print "rmdir($dir_name)\n"; + $noaction || + rmdir($dir_name) || + "Could not rmdir directory `$dir_name'! Reason: $!\n"; +} + |