View Full Version : Pulling from a directory

12-12-2007, 04:13 PM
I'm wanting to be able to look into a certain directory and pull whatever is in there and make it a link on the page so the person that is vewing it can pull up what is in that directory. All that is going to be in the directory is going to be documents, and I don't want to have to edit my html document every time there is a new file put into the directory. Is there a way to do this in HTML?

12-12-2007, 04:27 PM
do you have an example, like maybe from an existing web page?

12-12-2007, 04:27 PM
No, but there is in php:

//write to files before loading them

//needs adding

//function creation
function DirList($dir,$align) {
echo "<table align='$align'>";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$link = $dir."/".$file;
if(is_dir($dir."/".$file)) {
echo "<tr><td id='dirlist'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Directory '$link'</b></td></tr>";
echo "<tr><td id='dirlist'>"; DirList($link,$align); echo "</td></tr>";
} else {
echo "<tr><td align='left' id='file'>&nbsp;&nbsp;&nbsp;<a href=\"$link\">$link</a> - ".filesize($link)." bytes.</td></tr>";
if($i <= 0) {
echo "<tr><td align='left' id='file'>&nbsp;&nbsp;&nbsp;-- Folder is empty --</td></tr>";
echo "</table>";



The formatting is realyl bad and I'd like to add that I didn't write it and haven't had a play with semantics on it yet... but it basically prints out links to all of the files in a certainly directory.

You will need a server that runs php to do this tho and have a .php extension on the file

12-12-2007, 06:49 PM
yeh, you'll need a server side language for that.

heres how to do it more quickly in perl :p

my $Filepath = "location of your directory";

while(my $files=readdir($dir)){
next unless -d $Filepath.$files && $files!~/^\.+$/;
print qq(

foreach $itemInMenu (sort @fileNamesToShow) {
print qq(
print qq(

Now if you add new files to your directory, they will show in a list, automatically.