Find files with JavaScript - Code Modification Required

Guys, I have found some javascript code on the web that i need to modify to complete a task I have been assigned at work.  The code can be found here: http://www.codeproject.com/Articles/2019/Find-files-with-JavaScript and i have attached the file.  

I have a couple of requirements.

The code to run automatically upon the page loading - Is it possible for the code the run automatically when the page loads, so when you open the search.htm page, it simply displays the directory content for the folder hard coded in the webpage?

Hyperlinks to listed files - Could the files listed be hyperlinks to allow the users to click on the files and they open.

Multiple folder outputs - I would need to list multiple folders, so could the code be coded so that I could, say have a

Var1:folder1 path
var2: folder2 path,
etc.

Can someone please help as i have no idea how to modify the code, or if it is even possible.
****************
Search.htm
creativepresenceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Before anything else you do realize this won't work in IE11 (and probably IE10 - cannot remember) without the user manually enabling ActiveX and giving it permission.
Is this in a private intranet or for the internet?
0
creativepresenceAuthor Commented:
Thats fine, its for a private internet with just me and a handful of service desk colleagues using the page and have already identified the settings in IE to change. Just need to figure out the code.
0
creativepresenceAuthor Commented:
should read "Intranet"
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GaryCommented:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<style>
.Field {color: black; border: 1px solid #FFFFFF; background-color: #FFCC00;}
.Find  {color:blue; font: 10px Arial;}
</style>
<script>

var Fo =new ActiveXObject("Scripting.FileSystemObject");
var StrOut = new String();
var FileName = new String();
var Extention = new String();

function FindFile(FOo)
{
	var FSo = new Enumerator(FOo.Files);
	for(i=0;!FSo.atEnd();FSo.moveNext())
	{
		if(FileName == "*" ||  FSo.item().name.slice(0,FSo.item().name.lastIndexOf(".")).toLowerCase().indexOf(FileName)>-1)
			if(Extention == "*" || FSo.item().name.slice(FSo.item().name.lastIndexOf(".")+1).toLowerCase().indexOf(Extention)>-1){
				StrOut += "<tr "+ ((i%2)? "":"bgcolor=#DDAA55")  +"><td width=50%><font class=find>" + '<a href="file:///'+FSo.item().name+'">'+FSo.item().name + "</a></font></td><td width=25%><font class=find>" + FSo.item().type + "</font></td><td width=50%><font class=find>"+ String(FSo.item().size/(1024*1024)).slice(0,3) +" MB</font></td></tr>";
				i++
				}
	}
}

function Scan()
{

	FileName = (search.value.lastIndexOf(".")>-1)? search.value.slice(0,search.value.lastIndexOf(".")):(search.value.length>0)? search.value.toLowerCase():"*"; //Get Searched File Name
	Extention = (search.value.lastIndexOf(".")>-1)? search.value.slice(search.value.lastIndexOf(".")+1).toLowerCase():"*"; // Get Searched File Extention Name

	if(path.value.length>0 && Fo.FolderExists(path.value)){
		StrOut = "<table border=0 width=100% cellspacing=0>"
		FindFile(Fo.GetFolder(path.value));
		outPut.innerHTML = StrOut+"</table>";
		}
	else alert("Insert Correct Path Address");
}
</script>

<BODY topmargin="0" leftmargin="0" onload="Scan()">

<table border=0 width=100% cellspacing="0" style="border-collapse: collapse" cellpadding="2"><tr>
	<td dir="ltr" bgcolor="#FFCC00"><b><font face="Arial" size="2">Named :
    </font></b> </td>
	<td dir="ltr" bgcolor="#FFCC00">
    <input size=50 type=text id=search name=search class="Field"></td>
	</tr><tr>
	<td dir="ltr" bgcolor="#FFCC00">
    <p dir="ltr"><b><font face="Arial" size="2">Path : </font></b> </td>
	<td bgcolor="#FFCC00">
    <input size=50 type=text value="C:\" id=path name=path class="Field" ></td>
	</tr><tr>
	<td bgcolor="#FFCC00">&nbsp;</td>
	<td bgcolor="#FFCC00">
    <input type=button value="        Scan          " onclick=Scan() class="Field"></td>
	</tr><tr>
	<td colspan=2 align=right bgcolor="#FFCC00"><font face=arial size=2><b>Search Result</b></font><hr></td>
	</tr><tr>
	<td colspan=2 bgcolor="#FFCC00"><div id=outPut></div></td>
	</tr></table>
</BODY>
</HTML>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creativepresenceAuthor Commented:
Hi Gary, thats great and thanks very much.  Is there are way to use the code multiple times within the page?  with the least overhead and also the input boxes not to be visible. So ultimately, the user loads the page and is displayed with a list of files from various folders.

New start processes
List of docs
{list file path in the var, that then calls the code and displays the list of docs in the folder in the var}

Leavers Process
Another List of doc
{list another file path in the var, that then calls the code and displays another list of docs in the folder in the var}

Transfer Processes
Another List of docs.
{another list file path in the var, that then calls the code and displays another list of docs in the folder in the var}
0
creativepresenceAuthor Commented:
Hi, slowly getting there, i have it displaying the docs, last modified date & size, plus none of the form details, but ideally as above, need to be able to display multiple folders, plus if there are folders within the displayed folder, to also display the folders.  Also, ideally, exclude i guess hidden or atleast the thumbs.db file. Oh, and ideally file links to open in new window.  

Source:  \\Server\path\path\path\

New Starter Setup Procedure.doc                Fri May 16 14:11:40 UTC+0100 2014            2.6 MB
Thumbs.db    (needs to be hidden.              Tue May 15 15:34:59 UTC+0100 2012          0.0 MB
New Starter Setup Checklist.doc                  Tue Sep 24 12:45:46 UTC+0100 2013           2.4 MB
Folder1 (need to be able to see any folders and ideally linked).

I will endevour to try and figure it out, but any help would be appreciated.
0
GaryCommented:
Have a read thru the 4guysfromrolla article
http://www.4guysfromrolla.com/webtech/faq/FileSystemObject/faq5.shtml

Don't know if I have time today to do anything.

To open in a new window add target="_blank" to the anchor tag
0
GaryCommented:
Ignore the link about its the wrong type

To hide hidden files

function FindFile(FOo)
{
	var FSo = new Enumerator(FOo.Files);
	for(i=0;!FSo.atEnd();FSo.moveNext())
	{
		if(FileName == "*" ||  FSo.item().name.slice(0,FSo.item().name.lastIndexOf(".")).toLowerCase().indexOf(FileName)>-1)
			if(Extention == "*" || FSo.item().name.slice(FSo.item().name.lastIndexOf(".")+1).toLowerCase().indexOf(Extention)>-1){
			if (FSo.item().Attributes & 2 ){}
			else{
				StrOut += "<tr "+ ((i%2)? "":"bgcolor=#DDAA55")  +"><td width=50%><font class=find>" + '<a href="file:///'+FSo.item().name+'">'+FSo.item().name + "</a></font></td><td width=25%><font class=find>" + FSo.item().type + "</font></td><td width=50%><font class=find>"+ String(FSo.item().size/(1024*1024)).slice(0,3) +" MB</font></td></tr>";
				i++
				}
			}
	}
}

Open in new window

0
creativepresenceAuthor Commented:
Hi Gary/Plus Others, from my reading it would seem that the "outPut.innerHTML" command isnt fit for my purpose as the content is over written with the new content everytime its loaded.  Are they any other alternative commands that will work with the above code to display multiple folder contents? It would be really cool if I could get this sorted as it would get me some serious brownie points at work.
0
creativepresenceAuthor Commented:
Thanks for your assistance, although my issue is still not fully resolved.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.