Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,179
    Thanks
    174
    Thanked 257 Times in 257 Posts
    do you have an example, like maybe from an existing web page?

  • #3
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    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

  • #4
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •