#!/usr/bin/perl -w
#
# $Revision: 1.2 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/isempty,v $
# $Host: sys7.com $
# $UUID: 1cb6df45-e75a-3ec8-a932-cb2f0e1a83b4 $
#
#<isempty: accept list of paths, print only empty directories.

use strict;
my ($dir, $dh, @files);

while (<>) {
    chomp;
    $dir = $_;
    next unless -d "$dir";

    if (opendir($dh, "$dir")) {
        @files = readdir($dh);
        closedir($dh);
        print "$dir\n" if $#files == 1;    # only '.' and '..'
    }
    else {
        warn "$dir: $!\n";
    }
}

exit(0);
