Solved

Dynamically Enumerating Files

Posted on 1998-12-07
3
150 Views
Last Modified: 2013-12-25
I'm looking to make a real simple script.  Heres what I want to accomplish.
Have the script look in a specific directory, enumerate all the ".htm" files and then output in HTML links to those pages in that directory.  I know it's real easy to do, but I have never worked with this before.  It was kind of shoved into my lap.
This is going to be on an NT server running IIS4.0 and Active State.   I'm really unsure on how to enumerate the files, I think I can figure out the HTML output by example, but I haven't seen any examples that would help me out with extracting the file names and such.  If anyone has an example similiar to this or can just help me out it would be really appreciated. Thanks.
=Blain
0
Comment
Question by:timberbt
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1830042
Here it is in perl:

print "Content-type: text/html<br>\n\n";
my($dir) = "C:\\users\\Powers";
opendir(DIR, $dir) || die "Unable to open $dir: $!";

my(@files) = grep {/\.htm$/i && -f "$dir\\$_"} readdir(DIR);
foreach (@files) {
    print "<a href=\"$dir\\$_\">$_</A><br>\n"
}


0
 
LVL 1

Author Comment

by:timberbt
ID: 1830043
That seems to work great, but I'm having one other problem which may or may not be related.  I can run that just fine from the command prompt on NT, and the HTML looks to be correct.  But when I open it with a browser it will still run the script, ( I see a little command window pop up) but the HTML is not loaded into the browser.  What exactly am I missing?  Thanks!
=Blain
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1830044
It's not related at all... your server is not correctly configured.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question