Click to See Complete Forum and Search --> : Readdir question


boredcrazy
03-28-2001, 01:30 AM
The path to my live folder on my virtual host is:
/home/napkin/public_html/

When I run this code, it returns a blank page when I know for a fact that I have an index.htm in that folder.

What am I doing wrong?


#!/usr/bin/perl

#I'm assuming this is
#where I am on the server.
$PathToLiveFolder = "/home/napkin/public_html/";

#Open the main folder and split
#the file names into an array
opendir (WWW, $PathToLiveFolder);
@filenames = readdir (WWW);
closedir (WWW);

#Print HTTP_Header and intro line
print "Content-type: text/html\n\n\";
print "All the files and folders should be listed here.<br>";

#Print out the name of each file in the array
$x = 0;
while($x < @filenames)
{
print "-".$filenames[$x]."<br>";
$x++;
}

#Display file count
print "<br>There were this many files:".@filenames;

jemfinch
03-28-2001, 04:40 AM
What you're doing wrong is using perl.


#!/usr/bin/env python

import os

path = '/home/napkin/public_html/'
filenames = os.listdir(path)

print 'Content-type: text/html\r\n\r\n'
print 'All files and folders should be listed here<br>\n'

for file in filenames:
print '-', file, '<br>'

print '<br>There were this many files: ', len(filenames)


Jeremy

[ 28 March 2001: Message edited by: jemfinch ]

kmj
03-28-2001, 10:40 AM
Did you try viewing the source for the page?

Don't you need to enclose the page in <HTML><BODY> </BODY></HTML> tags???

kel
03-28-2001, 10:44 AM
Originally posted by jemfinch:

What you're doing wrong is using perl.

Spoken like a true Python-Nazi :D

TheLinuxDuck
03-29-2001, 02:01 PM
boredcrazy:

Please ignore jemfinch, he has gone insane termporarily, and will return to semi-normal behavior once this whole 'python' thing is out of this system. :)

And, the answer to your question is 'what kmj said'. You didn't enclose the html document in the appropriate html tags.

Here is some sample perl code to wet your whistle:

#!/usr/bin/perl -wT
use strict;

sub error($);

my($path)="/home/bored/public_html/";
print "Content-type: text/html\n\n\<html><head><title>Dir listing of $path",
"</title></head><body>";

if(opendir WWW, $path) {
my($file)=0;
my($dir)=0;
foreach(grep !/^\.\.?$/, readdir WWW) {
print "- $_";
print " [dir]<br>\n" and ++$dir and next if(-d "$path$_");
print "<br>\n" and ++$file;
}
print "<br>Files: $file<br>Dirs: $dir";
}
else {
print "<h1>ERROR!</h1>Cannot open dir $path: $!";
}

print "</body></html>";
exit;