LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   HELP: PERL script to retrieve file listing (https://www.linuxquestions.org/questions/programming-9/help-perl-script-to-retrieve-file-listing-324861/)

xboxter 05-18-2005 09:24 PM

HELP: PERL script to retrieve file listing
 
Hello,

I am trying to write a portion of a perl script where I want to output the file listing of a directory, but only outputting files and not showing directories. Is this possible to do in PERL? If it helps, I am also using Perl's NET::FTP class.

Thanks in advance,

Xboxter.

keefaz 05-19-2005 03:45 AM

If you want just to see regular files, try :

Code:

#!/usr/bin/perl

my $dir = '/etc';

opendir MYDIR, $dir or
    die "Can't open $dir: $!";

while( my $file = readdir(MYDIR) ) {
    next if not -f "$dir/$file";
    print "filename: $file\n";
    print "full path: $dir/$file\n\n";
}

closedir MYDIR;

I use the -f test to check if the file is a regular file

xboxter 05-19-2005 09:19 AM

Thanks alot keefaz, It worked great.

Xboxter


All times are GMT -5. The time now is 03:24 AM.