Computing.Net > Forums > Programming > Directory Listing Code Needed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Directory Listing Code Needed

Reply to Message Icon

Name: Jamie Rhine
Date: July 21, 2003 at 10:23:09 Pacific
OS: Win2K Pro SP3
CPU/Ram: AMD 1.4 GHz / 512 MB RAM
Comment:

Hello!

I am currently in the process of building a web site for the class that I teach. Throughout the course, I will be posting numerous documents for my students to download, and I am looking for a javascript or related script that will automatically keep a listing of the files in a certain directory on the site.

Basically, when a student visits the page, I want the script to automatically obtain a listing of the files in the specified directory so that they can click on a certain file and download it. With the vast number of documents that I will be adding, it would be very time consuming to have to go in and create a hyperlink to each document that I upload.

Thanks in advance for your help!


Best Regards,

Jamie Rhine



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: July 21, 2003 at 13:45:43 Pacific
Reply:

Javascript is unable to do this. You need a server-side scripting language to open the directory, read the files in it, and output the appropriate hyperlinks...Here is the meat of one in perl, which is one of the more popular server side languages:

#!/usr/bin/perl
print<<EndHTML;
<HTML>
<HEAD><TITLE>mypage</TITLE></HEAD>
<BODY>
EndHTML
$mydir="../mydir/assignments/";
opendir(DIR,$mydir);
@files=readdir(DIR);
foreach $file (@files)
{
   if (-f "$mydir$file")
   {
      print "<A href=\"$mydir$myfile\">click here</A><BR>\n";
   }
}
print "</BODY></HTML>";

Copy and paste the above into a text file, make the directory modifications and add any text you want, name it something.pl, upload it to the server, chmod 755 it (via your ftp program), and then go to yourserver/something.pl to test it.

The first line of the program is supposed to give the directory that perl is in...This depends on your server so if you don't know it, contact somebody in IT to find out. Then again, this post could be a huge waste of time if your school's server doesn't have perl.

Good luck,
-SN


0
Reply to Message Icon

Related Posts

See More


polygon shaped forms in v... Oracle manual start



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Directory Listing Code Needed

htaccess directory listings help www.computing.net/answers/programming/htaccess-directory-listings-help/15646.html

PHP Directory Listing www.computing.net/answers/programming/php-directory-listing/8345.html

PHP Customising Directory listing www.computing.net/answers/programming/php-customising-directory-listing/8290.html