[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Folder recursion and recognition problem



>I've been using both the DOS and Mac ports of PERL and am having trouble
>with folder recursion and folder recognition on the Mac.

Try something like this:

#!perl

$start = (shift @ARGV);
lstat($start);
$start =~ s/:$//;
print "$start\n";
&DoIt($start);

sub DoIt {
    local($it) = @_;
    local(@files);
    if (-d _) {
        opendir(DIR, $it.":");
        @files = readdir(DIR);
        closedir(DIR);
        foreach ( @files ) {
            lstat("$it:$_");
            unless (-d _) { print "$it:$_\n"; next }
            &DoIt("$it:$_")
        }
    }
}

You need full pathnames for <lstat>: <readdir> only gives the leaf-name.
This is a trap I fell into very noisily here a little while ago.

Regards,

Alan