JavaScript to display dir of files on website

P

Paul E. Schoen

I have switched to a new ISP which does not allow a directory listing of
files when an index.htm is not present. I have looked into server-side CGI
using Perl and it is certainly possible, but I don't think the ISP allows
CGI except for a special account. And after looking into Perl on the
comp.lang.perl.misc NG I don't think I want to learn it.

So, I made the following script which runs locally on the WSH and produces
an HTML file that I can upload to the same directory on my website, and it
seems to work OK. I could rename it index.htm or I could make my own index
file and provide a link to it for a clickable directory of files. Here is
the code:

============================================================

//Const ForReading = 1, ForWriting = 2, ForAppending = 8;

var objFSO, objFldr, objSFldr, objFl, objStream, sFile, sPath, sExtension;
var True = 1;
var ForWriting = 2;

// Create the FileSystemObject
objFSO = fso = new ActiveXObject("Scripting.FileSystemObject");

// The file you want the dir printed to...
sFile = ".\\FileDir.htm";

// The folder you want a dir of...
sPath = ".\\";

objStream = objFSO.OpenTextFile(sFile, ForWriting, True);

objStream.WriteLine("<html>\n");
objStream.WriteLine("<head>\n");
objStream.WriteLine("<title>Directory of Files</title>\n");
objStream.WriteLine("</head>\n");
objStream.WriteLine("<body>\n");
//objStream.WriteLine("<address>\n");

// Get the folder (line 24)
objFldr = objFSO.GetFolder(sPath);

fc = new Enumerator(objFldr.files);
var s;

for (; !fc.atEnd(); fc.moveNext()) {
s = fso.GetFileName(fc.item());
objStream.WriteLine ( '<a href="'+ s + '">' + s + '<br>');
}

objStream.WriteLine("</body>\n");
objStream.WriteLine("</html>\n");

objStream.Close();

==============================================================

I just have a few simple questions. (1) is there an equivalent to a
constant in JavaScript, (2) does objFSO need to be destroyed, and (3) is
there a way to do something like this on the server side so it will
dynamically reflect the folder contents. Otherwise if you see any errors or
problems in my code please feel free to make suggestions. I might work on
adding some formatting features to the HTML, and maybe some interactive
items in the JS, as a learning exercise.

Thanks,

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top