Hi,

     I am passing a directory into my perl program.  I want to list all
files only within that directory (do not descend to sub-directories).  I
have tried using the File::Find::find command but to no avail.

Here are some code snippets:
xi#!/usr/bin/perl -w
##############################################################################
#
#       May 01, 2001
#
#       prune_ADSM.pl
#
#       Changes:
#       05/01/01 CM     - Initial Creation
#
#############################################################################

use File::Find 'find';
use Getopt::Std;
use File::Spec 'curdir';

<snip>
# Get options from cmd line
getopt('d');

if ( $opt_d eq "" )
{
        $LOGDIR = ".";
}
elsif ( ! -d $opt_d )
{
        die("$0: directory $opt_d does not exist\n$usage\n");
}
else
{
        $LOGDIR = $opt_d;
}
<snip>
# Find all the log files within the directory
find( \&wanted, "$LOGDIR" );

print "@logs_old\n";

sub wanted
{
         if (  -f $File::Find::name )
         {
                my (@logfile_stat) = stat $File::Find::name;

                # add any log file whose modification time is less than
                # the last complete archives modification time
                if ($logfile_stat[9] < $last_full_log_seconds )
                {
                        push @logs_old, $File::Find::name;
                }
         }
        $File::Find::prune = 1;
}

I execute the script like so:
perl prune_ADSM.pl -d logdir (where logdir is in the current path)

Yet it does not return any valid files when I run it.  If I remove the -f
condition then only the logdir directory is shown and not the files within.
If I remove the prune flag from the example above then nothing is contained
in the array.  If both the file condition and the prune flag are removed
then all files and subdirectories are listed in entirety.

Any help on the use of the prune flag and why I cannot get the file test
condition to work are greatly appreciated.  As well as any other
suggestions.
-----------------------------------------
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]


Reply via email to