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



ultimategamer2k
User

Mar 10, 2001, 9:14 PM


Views: 351
list all files in a dir?

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

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


parham_m_s
journeyman

Mar 11, 2001, 5:57 AM


Views: 344
Re: list all files in a dir?

try this code:


Code
#!/usr/bin/perl 

print "Content-type:text/html\n\n";

$directory = "PATH TO DIR";

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

exit;

i just realized there was a double post of this :(

(This post was edited by parham_m_s on Mar 11, 2001, 5:00 AM)