Posted By

iblis on 08/06/07


Tagged

POSIX administration


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

melling


List empty directories


 / Published in: Perl
 

  1. #!/usr/bin/perl -w
  2. use strict;
  3. #
  4. # List empty directories
  5. # perl administration posix
  6. #
  7.  
  8.  
  9. # set start path
  10.  
  11. my $startpath = shift || '.';
  12.  
  13.  
  14. sub checkpath {
  15. my $path = shift;
  16. # open path or die
  17. opendir my($dir), $path
  18. or die "Can't open $path : $!\n";
  19. # debug
  20. #print "I am here: $path\n";
  21. # get directory content but skip . and .. (to avoid circular looping)
  22. my @content = grep {$_ !~ /^\.\.?$/} readdir $dir;
  23. # print directory name and exit if empty
  24. if (!@content) {
  25. print "$path\n";
  26. }
  27. # recurse trough directories
  28. foreach my $subpath (grep { -d "$path/$_"} @content) {
  29. checkpath($path.'/'.$subpath);
  30. }
  31. }
  32.  
  33. checkpath($startpath);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: iblis on February 9, 2008

Previous version was not doing the expected job

You need to login to post a comment.