Skip site navigation (1)Skip section navigation (2)
Date:      02 Sep 1999 12:56:06 +0200
From:      Dag-Erling Smorgrav <des@flood.ping.uio.no>
To:        "Rodney W. Grimes" <freebsd@gndrsh.dnsmgr.net>
Cc:        rgrimes@freebsd.org (Rodney W. Grimes), cvs-committers@freebsd.org, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/etc/mtree README
Message-ID:  <xzp1zchzint.fsf@flood.ping.uio.no>
In-Reply-To: "Rodney W. Grimes"'s message of "Sun, 22 Aug 1999 18:38:02 -0700 (PDT)"
References:  <199908230138.SAA33709@gndrsh.dnsmgr.net>

next in thread | previous in thread | raw e-mail | index | archive | help
"Rodney W. Grimes" <freebsd@gndrsh.dnsmgr.net> writes:
>     e)  Add missing and remove extra entries (producing this last one
>         is being a bit of a pain, anyone have a quick command to find
>         directories that have no entries in them?).

#!/usr/bin/perl5 -w

use strict;

sub recurse {
    my $base = shift;   # Where to start
    my @entries;        # Directory listing
    my $entry;          # Iterator for @entries
    local *DIR;         # Directory handle

    if ($base ne "/") {
        $base =~ s#/$##;
    }

    if (!opendir(DIR, $base)) {
        die("opendir(): $!\n");
    }
    if (!(@entries = readdir(DIR))) {
        die("readdir(): $!\n");
    }
    closedir(DIR);

    if (@entries == 2) {
        # Contains only . and .., no files or directories
        warn("$base/\n");
        return;
    }
    foreach $entry (@entries) {
        if (-d "$base/$entry" && $entry ne "." && $entry ne "..") {
            recurse("$base/$entry");
        }
    }
}

MAIN:{
    my $dir;            # Iterator

    if (@ARGV == 0) {
        die("Syntax: $0 dirname ...\n");
    }

    foreach $dir (@ARGV) {
        recurse($dir);
    }

    exit 0;
}

DES
-- 
Dag-Erling Smorgrav - des@flood.ping.uio.no


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzp1zchzint.fsf>