Professional Web Applications Themes

Help with script to list non-html files in folder - PERL Modules

Hi I have this code but it does not seem to list non-html files. Could anyone point me in the right direction. Thanks in advance Mark #!/usr/bin/perl print "Content-type: text/html\n\n"; # Define Variables $basedir = '../'; $baseurl = 'http://www.mywebsite.co.uk/'; files = (*.zip'); $title = "My Web Site"; # Get Files To Search Through &get_files; # Print Results of Search &return_html; sub get_files { chdir($basedir); foreach $file (files) { $ls = `ls $file`; ls = split(/\s+/,$ls); foreach $temp_file (ls) { if (-d $file) { $filename = "$file$temp_file"; if (-T $filename) { push(FILES,$filename); } } elsif (-T $temp_file) { push(FILES,$temp_file); } } ...

  1. #1

    Default Help with script to list non-html files in folder

    Hi

    I have this code but it does not seem to list non-html files.

    Could anyone point me in the right direction.

    Thanks in advance

    Mark



    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    # Define Variables
    $basedir = '../';
    $baseurl = 'http://www.mywebsite.co.uk/';
    files = (*.zip');
    $title = "My Web Site";

    # Get Files To Search Through
    &get_files;

    # Print Results of Search
    &return_html;

    sub get_files {

    chdir($basedir);
    foreach $file (files) {
    $ls = `ls $file`;
    ls = split(/\s+/,$ls);
    foreach $temp_file (ls) {
    if (-d $file) {
    $filename = "$file$temp_file";
    if (-T $filename) {
    push(FILES,$filename);
    }
    }
    elsif (-T $temp_file) {
    push(FILES,$temp_file);
    }
    }
    }
    }

    sub return_html {
    print "<html>\n";
    print "<head>\n";
    print "<title>Directory</title>\n";
    print "</head>\n";
    print "<body>\n";

    print "Contents of folder:<p>\n";

    foreach $FILE (FILES) {
    print "<a href=\"$baseurl$FILE\">$FILE</a></p>\n";
    }

    print "</body>";
    print "\n</html>";

    }

    mac Guest

  2. #2

    Default Re: Help with script to list non-html files in folder

    mac wrote:
    > Hi
    Since you are not using modules or asking a question about modules what made
    you decide that comp.lang.perl.modules was the correct newsgroup for this?

    > I have this code but it does not seem to list non-html files.
    What error or warning messages do you get? What does it "seem to list"?

    > Could anyone point me in the right direction.
    >
    >
    >
    > #!/usr/bin/perl
    Since this is a CGI program you should use taint mode and you should also
    enable warnings and strict.

    #!/usr/bin/perl -T
    use warnings;
    use strict;

    > print "Content-type: text/html\n\n";
    > # Define Variables
    > $basedir = '../';
    > $baseurl = 'http://www.mywebsite.co.uk/';
    > files = (*.zip');
    ^^
    You are missing a quote.
    > $title = "My Web Site";
    >
    > # Get Files To Search Through
    > &get_files;
    Why are you using a subroutine for code that will only run once? Why are you
    using Perl4 style subroutine calls?

    > # Print Results of Search
    > &return_html;
    >
    > sub get_files {
    >
    > chdir($basedir);
    You should verify that chdir() worked correctly.

    > foreach $file (files) {
    > $ls = `ls $file`;
    Is the ls command available? Why not use perl's built-in opendir/readdir or
    glob functions?

    > ls = split(/\s+/,$ls);
    What if your file names contain whitespace? Why not just use backticks in
    list context?

    > foreach $temp_file (ls) {
    > if (-d $file) {
    > $filename = "$file$temp_file";
    You are missing a directory separator between $file and $temp_file.

    > if (-T $filename) {
    > push(FILES,$filename);
    > }
    > }
    > elsif (-T $temp_file) {
    > push(FILES,$temp_file);
    > }
    > }
    > }
    > }
    >
    > sub return_html {
    > print "<html>\n";
    > print "<head>\n";
    > print "<title>Directory</title>\n";
    > print "</head>\n";
    > print "<body>\n";
    >
    > print "Contents of folder:<p>\n";
    >
    > foreach $FILE (FILES) {
    > print "<a href=\"$baseurl$FILE\">$FILE</a></p>\n";
    > }
    >
    > print "</body>";
    > print "\n</html>";
    >
    > }

    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

  3. #3

    Default Re: Help with script to list non-html files in folder

    Mac,

    I suggest you use File::Find, which is a stnadard part of Perl:

    [url]http://search.cpan.org/author/NWCLARK/perl-5.8.7/lib/File/Find.pm[/url]

    mac wrote:
    > Hi
    >
    > I have this code but it does not seem to list non-html files.
    >
    > Could anyone point me in the right direction.
    >
    > Thanks in advance
    >
    > Mark
    >
    >
    >
    > #!/usr/bin/perl
    > print "Content-type: text/html\n\n";
    > # Define Variables
    > $basedir = '../';
    > $baseurl = 'http://www.mywebsite.co.uk/';
    > files = (*.zip');
    > $title = "My Web Site";
    >
    > # Get Files To Search Through
    > &get_files;
    >
    > # Print Results of Search
    > &return_html;
    >
    > sub get_files {
    >
    > chdir($basedir);
    > foreach $file (files) {
    > $ls = `ls $file`;
    > ls = split(/\s+/,$ls);
    > foreach $temp_file (ls) {
    > if (-d $file) {
    > $filename = "$file$temp_file";
    > if (-T $filename) {
    > push(FILES,$filename);
    > }
    > }
    > elsif (-T $temp_file) {
    > push(FILES,$temp_file);
    > }
    > }
    > }
    > }
    >
    > sub return_html {
    > print "<html>\n";
    > print "<head>\n";
    > print "<title>Directory</title>\n";
    > print "</head>\n";
    > print "<body>\n";
    >
    > print "Contents of folder:<p>\n";
    >
    > foreach $FILE (FILES) {
    > print "<a href=\"$baseurl$FILE\">$FILE</a></p>\n";
    > }
    >
    > print "</body>";
    > print "\n</html>";
    >
    > }
    metaperl@gmail.com Guest

  4. #4

    Default Re: Help with script to list non-html files in folder

    I realise this is the wrong group and I have posted my message in
    another group.

    Thanks for taking the trouble to the repy

    Mark

    mac Guest

Similar Threads

  1. Intercept the auto-refresh of a folder in HTML folder template
    By George Valkov in forum Windows Server
    Replies: 0
    Last Post: June 7th, 07:38 PM
  2. Getting a list of files in a folder
    By Dave Navarro in forum ASP
    Replies: 7
    Last Post: October 16th, 08:06 PM
  3. PHP files not loading- html loading fine from the same folder!?
    By Prince Of Thieves in forum PHP Development
    Replies: 1
    Last Post: October 8th, 01:02 AM
  4. List Files in a Web Folder
    By J P Singh in forum ASP
    Replies: 1
    Last Post: September 5th, 03:10 PM
  5. Apply template to all HTML files in folder
    By Murray *TMM* in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 15th, 06:08 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139