Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-12-2007, 03:13 PM   PM User | #1
thedarkonecion
New to the CF scene

 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
thedarkonecion is an unknown quantity at this point
Exclamation Pulling from a directory

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?
thedarkonecion is offline   Reply With Quote
Old 12-12-2007, 03:27 PM   PM User | #2
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
do you have an example, like maybe from an existing web page?
jcdevelopment is offline   Reply With Quote
Old 12-12-2007, 03:27 PM   PM User | #3
ahallicks
Senior Coder

 
ahallicks's Avatar
 
Join Date: May 2006
Location: Lancaster, UK
Posts: 1,134
Thanks: 1
Thanked 57 Times in 55 Posts
ahallicks is on a distinguished road
No, but there is in php:

PHP Code:
<?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;
$i++;
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>";
continue;
} 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>";
}
closedir($handle);
}
echo 
"</table>";
}

DirList("pathtodirectory","left");

?>
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
__________________
"write it for FireFox then hack it for IE."
Quote:
Originally Posted by Mhtml View Post
Domains are like women - all the good ones are taken unless you want one from some foreign country.
Reputation is your friend

Development & SEO Tools
ahallicks is offline   Reply With Quote
Old 12-12-2007, 05:49 PM   PM User | #4
bazz
Master Coder

 
Join Date: Apr 2003
Location: in my house
Posts: 5,211
Thanks: 39
Thanked 201 Times in 197 Posts
bazz will become famous soon enoughbazz will become famous soon enough
yeh, you'll need a server side language for that.

heres how to do it more quickly in perl

Code:
my $Filepath = "location of your directory";
 
  opendir($dir,$Filepath);
    while(my $files=readdir($dir)){
      next unless -d $Filepath.$files && $files!~/^\.+$/;
      push(@fileNamesToShow,$files);
    }
    closedir($dir);
  }
    print qq(
      <ul>
    ); 

    foreach $itemInMenu (sort @fileNamesToShow) {
      print qq(
        <li>$itemInMenu</li>   
      );
    }
    print qq(
      </ul>
    );
Now if you add new files to your directory, they will show in a list, automatically.

bazz
bazz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.