Revision: 3514
Updated Code
at February 9, 2008 18:55 by iblis
Updated Code
#!/usr/bin/perl -w use strict; # # List empty directories # perl administration posix # # set start path my $startpath = shift || '.'; sub checkpath { my $path = shift; # open path or die opendir my($dir), $path or die "Can't open $path : $!\n"; # debug #print "I am here: $path\n"; # get directory content but skip . and .. (to avoid circular looping) my @content = grep {$_ !~ /^\.\.?$/} readdir $dir; # print directory name and exit if empty if (!@content) { print "$path\n"; return; } # recurse trough directories foreach my $subpath (grep { -d "$path/$_"} @content) { checkpath($path.'/'.$subpath); } } checkpath($startpath);
Revision: 3513
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 6, 2007 08:47 by iblis
Initial Code
#!/usr/bin/perl -w use strict; # # List empty directories # perl administration posix # # with comments my $path; $path = shift or $path = '.'; # set path from argument or default opendir my($dir), $path or die "Can't open $path : $!\n"; # open path or die my @dirs = grep { -d "$path/$_"} readdir $dir; # list directories in path foreach my $subpath (@dirs) { # loop through next if ($subpath =~ /^\.\.?$/); # skip . and .. (to avoid circular looping) opendir my($subdir), "$path/$subpath" or die "Can't open $subpath : $!\n"; # open subpath or die if (!(grep {$_ !~ /^\.\.?$/} readdir $subdir)) { # test if subpath has not other element than . and .. print "$subpath\n"; } }
Initial URL
Initial Description
Initial Title
List empty directories
Initial Tags
Initial Language
Perl