displaying directory in html

How would i in a csh script get it to display all the files in the current directory in html?

how do i write a csh script that constructs an HTML index page for files in the current directory or files on the command line?

Thanks

Presumably, you want more than just a listing of files (which can be produced without the intervention of any scripting language)?

If so, the script is called from a cgi bin and dynamically converts the data attributes (i.e. in this case a list of files) into valid HTML which is (usually) streamed to the browser.

The important line is the first output line which begins:

Content-type: text/html\n\n

The rest is just normal HTML encoding...

Your browser will probably let you view directories (if you are set-up as an ftp user on your unix box). Try using the following format in your browser's address bar... ftp://logname:password@unixhost/your/directory

If you don't want toenable apache's indexer for whatever reason, you can add this script, though it's in PHP:

(more revisions, etc. here: http://www.furry.ca/cgi-bin/furryca/forum/ikonboard.cgi?;act=ST;f=9;t=50 )

<?php
/* Karma's Funkii Index Script CopyLeft 2003 The Entity Known As Karma Foxx
  (karma@yiffy.tk - www.yiffy.tk)*/

// Opening Static HTML
print("
<html>\n<head>\n<title>Index</title>\n<style>
body
{
background-color: #FFFFFF;
font-size: 10pt;
font-family: Arial, Helvetica;
color: #000000;
}
a:link
{
color: #666666;
text-decoration: none;
}
a:visited
{
color: #666666;
text-decoration: none;
}
a:active
{
color: #666666;
text-decoration: none;
}
a:hover
{
color: #999999;
text-decoration: none;
}
img
{
border: 0px;
}
</style>\n</head>\n<body>\n<center>
<font size=\"+1\">\n<b>Index of ".exec("pwd")." | <a href=\"../\">Parent Directory</b></a>\n</font>
<table width=\"98%\" cellpadding=\"0\" cellspacing=\"2\" marginwidth=\"0\" marginheight=\"0\">
");

// Define functions

function makeThumb($image) // Makes a thumbnail of the file in question
{
if(! file_exists(".thumbs/".$image))
{
if(! is_dir(".thumbs"))
{
mkdir(".thumbs");
}

exec("convert -size 80x60 $image -resize 80x60 .thumbs/$image");
}
}

function tests($file) // Perform tests on the file, then output an array
{
if(is_file($file))
{
$image_types = array("\.png", "\.jpg", "\.jpeg", "\.jfif", "\.gif", "\.bmp", "\.xbmp", "\.tiff");
$document_types = array("\.txt", "\.doc", "\.rtf", "\.pdf", "\.ps", "\.eps", "\.sgml", "\.DocBook");
$web_types = array("\.htm", "\.html", "\.shtml", "\.php", "\.cgi", "\.pl", "\.js", "\.vb", "\.asp");
$output[type] = "File";
foreach($image_types as $ext)
{
$results = ereg($ext, $file);
if(gettype($results) == integer)
{
$output[type] = "Image";
}
}
foreach($document_types as $ext)
{
$results = ereg($ext, $file);
if(gettype($results) == integer)
{
$output[type] = "Document";
}
}
foreach($web_types as $ext)
{
$results = ereg($ext, $file);
if(gettype($results) == integer)
{
$output[type] = "Web";
}
}
}
elseif(is_dir($file))
{
$output[type] = "Directory";
}
$output[access] = date("D d M Y g : i A", fileatime($file));
$output = date("D d M Y g : i A", filemtime($file));
$output[changed] = date("D d M Y g : i A", filectime($file));
$output[name] = $file;
$temp_size = filesize($file);
// Format the file size
if($temp_size < 1024)
{
$output = $temp_size;
$output[sizetype] = "B";
}
elseif($temp_size < 1048576)
{
$output = round($temp_size /= 1024);
$output[sizetype] = "KB";
}
else
{
$output = round($temp_size /= 1048576);
$output[sizetype] = "MB";
}
// Check permissions
if(is_readable($file))
{
$permissions = "r";
}
else
{
$permissions = "-";
}
if(is_writable($file))
{
$permissions .= "w";
}
else
{
$permissions .= "-";
}
if(is_executable($file))
{
$permissions .= "x";
}
else
{
$permissions .= "-";
}
$output[permissions] = $permissions;

return $output;
}

function showItem($file)
{

// Set the icon directory
$icons = "file:/var/www/icons";
print("<tr>\n<td bgcolor=\"#E6E6E6\" onMouseOver=\"this.bgColor='#F6F6F6'\" onMouseOut=\"this.bgColor='#E6E6E6'\"><table border=\"0\" width=\"100%\" cellpadding=\"2\" marginwidth=\"0\" marginheight=\"0\" cellspacing=\"0\">\n<tr>\n<td width=\"80\" height=\"60\" valign=\"middle\" align=\"center\">");
if($file[type] == "Image")
{
makeThumb($file[name]);
print("
<a href=\"$file[name]\"><img src=\".thumbs/$file[name]\"></a>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>Image Name: </b><a href=\"$file[name]\">$file[name]</a><br>
");
}
elseif($file[type] == "Web")
{
print("
<a href=\"$file[name]\"><img src=\"$icons/web.png\"></a>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>Document Name: </b><a href=\"$file[name]\">$file[name]</a><br>
");
}
else
{
print("
<a href=\"$file[name]\"><img src=\"$icons/$file[type].png\"></a>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>$file[type] Name: </b><a href=\"$file[name]\">$file[name]</a><br>
");
}

print("
<b>Size: </b>$file $file[sizetype]<br>
<b>Permissions: </b>$file[permissions]<br>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>Uploaded: </b>$file[changed]<br>
<b>Modified: </b>$file<br>
<b>Accessed: </b>$file[access]<br>
</td>
</tr>
</table>\n</td>\n</tr>
");
}

// Feed directory contents into an array
$dh = opendir(".");
while(gettype($entries[] = readdir($dh)) != boolean)
{
$entries[] = readdir($dh);
}
closedir($dh);
sort($entries);

foreach($entries as $file)
{
// Exclude this document and the parent dirs from the list
if($file == "index.php" or $file == "" or $file == "." or $file == ".." or $file == ".thumbs")
{
continue;
}
showItem(tests($file));
}

// Ending Static HTML
print("</table>\n<font size=\"-1\">
This page generated on ".date("D d M Y g : i A")." by Karma's Funkii Index Script<br>
<a href=\"mailto:karma@yiffy.tk\">Contact</a> Karma - <a href=\"http://www.yiffy.tk\">www.yiffy.tk</a>
</font>\n</center>\n</body>\n</html>");

?>

A demonstation of this script can be found at http://karma.luniac.com/misc .

Please don't double-post, adel66. That way, any answers anyone gives you to help out will all be one place.

I merged the threads, so I deleted the link to the now non-existent thread. --- Perderabo

Sorry its just that i thought i put my first post in the wrong message board thats all.

THanks.

im trying to test csh scripts on windows using cygwin, but its saying that

bash: csh: command not found.

How do i get cygwin working so that i can use it like a unix shell?

Im still trying to do the csh script that displays the directory in html

This is what ive got so far: (cant test it due to my cygwin not doing what i want it to)

#!/bin/csh -f

ls

This should list the files in the current directory, but what do i write to make it output in html to a html file?

A working example would help me.

I don't use csh, but this might work...

ls | awk 'BEGIN{print "<HTML><HEAD></HEAD><BODY><PRE>"}1;END{print "</PRE></BODY></HTML>"}' >dirlist.html