www.webdeveloper.com
Results 1 to 6 of 6

Thread: Directoies Exclusion

  1. #1
    Join Date
    Sep 2014
    Posts
    11

    Directoies Exclusion

    Hi, I'm trying to show only HTML files in my root web directory.

    So all other files (including .xml) need to be excluded. I know about the . and how it excludes the htaccess and other . files, so that has to stay.

    Code:
    my $coredir=$ENV{'DOCUMENT_ROOT'};
    opendir(DRA, $coredir) || die("Cannot open directory");
     my @thefiles=readdir(DRA);
     foreach my $f (@thefiles) {
      unless ( ($f eq ".") || ($f eq "..") )
      {print qq ~$f<br>\n~;}
     }
    closedir(DRA);
    I do have a robots.txt file there, but the bots pick that up anyways, so don't need it showing either.

    It's probably only a couple of lines of code, but I don't know how. I'm trying to avoid calling in a big module for something this simple.

    Hope you can help - thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Could you use glob("*.html") to get your file list?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2014
    Posts
    11
    Thanks, NogDog. It's been years and I forgot about glob - duh.
    Code:
    my $coredir=$ENV{'DOCUMENT_ROOT'};
    my @cf = glob "$coredir/*.html";
    foreach my $cf (@cf) {
     my($rt, $cf) = $cf =~ m{(.+)/([^/]+)$};
     print qq ~$cf<br>~;
    }
    This ended up producing a basic xml sitemap from a few lines of code (including the .xml file with an SSI) - a total of 633 bytes. All the bot wants is a file and could care less about the code running it. It lists the site files in the web root and the blog files from their directory.

    Would you believe I ran across one with 3087 big lines of code to do exactly the same thing! I wonder about the overkillers sometimes (must take 'em a year just to do one days shop in a supermarket).

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    I've been away from Perl for a long time, but PHP has a version of glob(), which rung a bell in my memory vaults when I saw your post.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Sep 2014
    Posts
    11
    I know nothing about PHP, avoided it because of all the exploits and lack of compatibility with previous versions, plus didn't want to pick up another language. My Perl isn't great, but it works and what I do is geared for what's out there - mainly 5.8 and earlier on web hosts. Still got to figure out how to exclude certain html files (like that Google one we have to keep on our sites and one or two others). Should keep me busy in spare moments over the holiday season

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Hackers exploit PHP programmers, not PHP -- but that's true about any language. It's all good, and whatever works, works. I was in no way meaning to disparage Perl. (Just don't get me started on Ruby. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles