Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-18-2005, 09:24 PM   #1
LQ Newbie
Registered: May 2005
Posts: 6

Rep: Reputation: 0
Exclamation HELP: PERL script to retrieve file listing


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,

Old 05-19-2005, 03:45 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,345

Rep: Reputation: 390Reputation: 390Reputation: 390Reputation: 390
If you want just to see regular files, try :


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
Old 05-19-2005, 09:19 AM   #3
LQ Newbie
Registered: May 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks alot keefaz, It worked great.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Script to download file apt Programming 4 10-19-2005 08:33 AM
include a file in perl script Ateo Programming 1 04-22-2005 09:53 PM
ProFTP problem: can login but not retrieve directory listing Singing Banzo Linux - Networking 4 03-23-2005 12:11 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
PHP Script to retrieve queries from log file saravanan1979 Programming 1 03-17-2002 08:13 AM

All times are GMT -5. The time now is 11:12 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration