From afa99ef07d74e993ac86811e24177f5818aa855b Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 17 Feb 2012 18:06:22 +0100 Subject: remove empty directories --- videomv.pl | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'videomv.pl') diff --git a/videomv.pl b/videomv.pl index a21bc33..004f51e 100755 --- a/videomv.pl +++ b/videomv.pl @@ -542,6 +542,11 @@ if (defined $old_symlink) { &perform ("Deleting old symlink... ", unlink $old_symlink); } +open my $DIR, catdir($directors, $old_director) or die "Can't open: $!"; +if (scalar(grep( !/^\.\.?$/, readdir(DIR)) == 0)) { + &perform ("Removing empty dir... ", rmdir catdir($directors, $old_director)); +} +closedir DIR or die "Can't close: $!"; &perform ("Creating new symlink... ", symlink catfile(updir(),'DIRECTORS',$new_director,$new_filename), @@ -635,6 +640,10 @@ sub revert { $actions[0] = 'Deleting'. $1; $rev = unlink $new_symlink; } + elsif ($actions[0] =~ /^Removing( empty dir.*)/) { + $actions[0] = 'Creating'. $1; + $rev = mkdir catdir($directors, $old_director); + } else { print STDERR "Error: unknown action `" .$actions[0]. "'!\n"; $actions[0] = undef; -- cgit v1.2.3