#!/usr/bin/perl -w
#
# $Revision: 1.2 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/emptydir,v $
# $Host: sys7.com $
# $UUID: c19b5296-e9c6-30bc-a056-825fb7f39b4e $
#
#<emptydir: accept one or more directories, print empty ones.

use strict;

foreach my $dir (@ARGV) {
    if (opendir(my $dh, "$dir")) {
        my $k = 0;
        while ($_ = readdir($dh)) {
            chomp;
            next if $_ eq '.' || $_ eq '..';
            $k++;
            last if $k > 1;
        }
        closedir($dh);

        print "$dir\n" if $k == 0;
    }
    else {
        warn "$0: $dir: opendir failed: $!\n";
    }
}

exit(0);
