CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
list all files in a dir?

 



ultimategamer2k
User

Mar 10, 2001, 9:14 PM

Post #1 of 6 (482 views)
list all files in a dir? Can't Post

what is the code to print all the names of files to a browser?

visit my web site at http://ultimategamer.cjb.net


japhy
Enthusiast

Mar 10, 2001, 9:26 PM

Post #2 of 6 (480 views)
Re: list all files in a dir? [In reply to] Can't Post

Read perlfunc for the following functions: opendir, readdir, and closedir; or, for a different approach, glob.


Code
perldoc -f opendir 
perldoc -f readdir
perldoc -f closedir
perldoc -f glob

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


ultimategamer2k
User

Mar 10, 2001, 9:29 PM

Post #3 of 6 (478 views)
Re: list all files in a dir? [In reply to] Can't Post

ummm.... okay... can u give me an example?

visit my web site at http://ultimategamer.cjb.net


japhy
Enthusiast

Mar 10, 2001, 9:34 PM

Post #4 of 6 (477 views)
Re: list all files in a dir? [In reply to] Can't Post

No.

But you could read the documentation like I asked, where you would find examples of their uses. Read the docs from your command-line with the perldoc program (if you have perl, you have perldoc). Or, click the Perl Documentation link here or on the sidebar on the left.

If you take the time to read the docs, you'll be a lot smarter, and you'll learn a lot more. Honestly.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


ultimategamer2k
User

Mar 11, 2001, 7:31 AM

Post #5 of 6 (471 views)
Re: list all files in a dir? [In reply to] Can't Post

what about the ls command??

visit my web site at http://ultimategamer.cjb.net


ultimategamer2k
User

Mar 11, 2001, 8:29 AM

Post #6 of 6 (467 views)
Re: list all files in a dir? [In reply to] Can't Post

well.. i used this

#!/usr/bin/perl
use CGI qw(:standard);
print "Content-type:text/html\n\n";
$dir = param('dir');
$directory = "$dir";

opendir (DIR,$directory);
@files = readdir(DIR);
closedir (DIR);
foreach $file (@files) {
if ($file ne ".") {
if ($file ne "..") {
print "$file\n";
}
}
}

exit;

and i put this into my browser http://ultimategamers.gamersfuture.com/cgi-bin/test2.pl?dir=playstation

and i get this in the error log

[Sun Mar 11 11:25:57 2001] [error] [client 24.123.326.223] File does not exist: /home/nox/public_html/ultimategamers/500.shtml
[Sun Mar 11 11:25:57 2001] [error] [client 24.123.326.223] Premature end of script headers: /home/nox/public_html/ultimategamers/cgi-bin/test2.pl

and i dont know what to do!!!!


visit my web site at http://ultimategamer.cjb.net

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives