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: Intermediate:
Displaying a directory

 



benchivers
Deleted

Dec 28, 2000, 1:04 PM

Post #1 of 3 (304 views)
Displaying a directory Can't Post

How do you dislay the list of files in a directory in an html page? Please help me!



Maebius
Novice

Dec 29, 2000, 8:50 AM

Post #2 of 3 (294 views)
Re: Displaying a directory [In reply to] Can't Post

Well, it really depends on what type of files you want listed.
All files? If so, here is a quick and dirty script that should do
that. (note, all paths and filenames are generic and should
be altered to suit your site).

$dir= shift || '.';
opendir DIR, $dir or die "Can't open directory $dir: $!\n";
while ($file= readdir DIR) {
print "Found a file: '$file'\n";
}

Note that this will return the ENTIRE contents of the directory
(including the other directories '.' and '..')

In order to just find actual files, you might want to try
something like this:

while ($file= readdir DIR) {
next if $file=~/^\./;
print "Found a file: '$file'\n";
}

is a decent workaround for this.


I'm sure there are even better ways of doing this, but this particular method works for me.


living life -umop apisdn-
maebius@everthorn.net


Mortimer
journeyman

Dec 30, 2000, 9:30 PM

Post #3 of 3 (288 views)
Re: Displaying a directory [In reply to] Can't Post

But what about the files whose names begin with '.' ? You'll miss them with:


Code
$file=~/^\./;

Rather do:


Code
$file=~/^\.$/ || $file=~/^\.\.$/;

Dave (Wannabe Perl hacker).
www.dmscripts.com - davemortimer@one.net.au


 
 


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

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