LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 0
Exclamation 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.
 
Old 05-19-2005, 03:45 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

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

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

Xboxter
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 AM.

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