Web Analytics Made Easy -
StatCounter Pulling every .txt file from a dir - CodingForum

Announcement

Collapse
No announcement yet.

Pulling every .txt file from a dir

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pulling every .txt file from a dir

    hey there,
    ok ive been working on quite a big script,
    and got to part i cant work out....
    the script should pull all the ,txt files form a dir and display them inbeded in html so there is one then next uisng <br> also should be alphabetical but im getting now where...the rest of the code fine..now i just need to finish it with this part of code can someone help me out here?
    thanks aload
    sir p
    Reseller Web Hosting - Unlimited websites from $5.49
    cakephp tutorials || Buying or sell websites? Do it here, free! || Professional Website & PHP development

    Freelance Magento Job Classifieds

  • #2
    I'm working on it

    Here's what I got:
    Code:
    #!/usr/bin/perl
    
    opendir(DIR,".");
    @files = sort(grep(/\.php$/,readdir(DIR)));
    closedir(DIR);
    
    print "Content-type: text/html\n\n";
    
    $all_data = "";
    foreach $file (@files) {
    	open(FILE,"$file") || die("Could not find $file. $!");
    	@lines = <FILE>;
    	close(FILE);
    	foreach $line (@lines) {
    		$line =~ s/\n/\<br\>/g; # optional
    		$line =~ s/\</&lt;/g; # optional
    		$all_data .= "$line";
    	}
    	$all_data .= "<br>";
    }
    
    print $all_data;
    I hope it's useful to you.

    Mzzl, Chris
    Last edited by chrisvmarle; Jun 20, 2002, 09:51 AM.
    My Website
    010100010011110101110100011011110111000001101000

    Comment


    • #3
      hey thanks
      gives an error tho/
      the logs say file does not exsist ...this is not true or it would be 404...any ideas?
      Reseller Web Hosting - Unlimited websites from $5.49
      cakephp tutorials || Buying or sell websites? Do it here, free! || Professional Website & PHP development

      Freelance Magento Job Classifieds

      Comment


      • #4
        Oops, I tested it with my .php files 'cuz I didn't have any .txt files in my cgi-bin. And I found another little problem. Here is the new code, try this:
        Code:
        #!/usr/bin/perl
        
        opendir(DIR,".");
        @files = sort(grep(/\.[b]txt[/b]$/,readdir(DIR)));
        closedir(DIR);
        
        print "Content-type: text/html\n\n";
        
        $all_data = "";
        foreach $file (@files) {
        	open(FILE,"$file") || die("Could not find $file. $!");
        	@lines = <FILE>;
        	close(FILE);
        	foreach $line (@lines) {
        		$line =~ s/\</&lt;/g; # optional
        		$line =~ s/\n/\<br\>/g; # optional
        		$all_data .= "$line";
        	}
        	$all_data .= "<br>";
        }
        
        print $all_data;
        Mzzl, Chris
        My Website
        010100010011110101110100011011110111000001101000

        Comment


        • #5
          ok cool,
          still does the same thing....im thinking it means the dir is missing...i cant see in there where the dir is? it looks like the dir is " . "
          Reseller Web Hosting - Unlimited websites from $5.49
          cakephp tutorials || Buying or sell websites? Do it here, free! || Professional Website & PHP development

          Freelance Magento Job Classifieds

          Comment


          • #6
            opendir(DIR,".");
            "." is indeed the directory. It means "current dir", so this script opens the current dir, wich is where your script is running in.

            You can change the dot to anything you want. Like "texts" to open a dir named "texts".

            Mzzl, Chris
            My Website
            010100010011110101110100011011110111000001101000

            Comment


            • #7
              hey Chris,
              ok it works with no erros but does not display the info and I have changed it abit..still no errors but if you look at the code then test it yourself look what happens
              im stumped...you got any ideas?
              or anyone elsE?
              cheers
              heres the code for this....
              print "Content-type:text/html\n\n";

              parse_form();

              $int =$FORM{int};
              $band =$FORM{band};

              sub parse_form {

              print "<html><head><title>TabbersTemple.com - $int tabs for $band </title></head>\n";
              print "<body bgcolor=\"#000000\" text=\"#FFFFFF\">\n";
              print "<b><small><font face=\"Verdana\">$int Tabs for $band </font><br>\n";

              opendir(DIR,"../tabberstemple/tabs/$int/$band");
              @files = sort(grep(/\.txt$/,readdir(DIR)));
              closedir(DIR);

              $all_data = "";
              foreach $file (@files) {
              open(FILE,"$file") || die("Could not find $file. $!");
              @lines = <FILE>;
              close(FILE);
              foreach $line (@lines) {
              $line =~ s/\</&lt;/g; # optional
              $line =~ s/\n/\<br\>/g; # optional
              $all_data .= "$line";
              }
              $all_data .= "<br>";
              }

              print $all_data;
              }
              thanks
              sir p
              Reseller Web Hosting - Unlimited websites from $5.49
              cakephp tutorials || Buying or sell websites? Do it here, free! || Professional Website & PHP development

              Freelance Magento Job Classifieds

              Comment

              Working...
              X