Display local folder content (sub folders & files (not hidden)) using JavaScript

creativepresence
creativepresence used Ask the Experts™
on
Guys, slowly getting a solution that works for me via here, but still not completely there.  I work on a helpdesk and want to create a webpage that will display a htm/html page showing the content of multiple networked folders, such as

VAR: Folder path
NEW STARTER PROCESS
Folder 1
Folder 2
Doc 1
Doc 2
...
Doc 7

VAR: another folder path
LEAVERS PROCESS
Folder 1
Folder 2
Doc 1
Doc 2
...
Doc 7

with the folder and document links clickable to open in a new page.  Someone on here has helped part way, but only to display the content (files) of one folder.

This is what I have so far...

HTML
<html>
<head>
<script src="scripts/filelist.js"></script>
</head>
<BODY topmargin="0" leftmargin="0" onLoad="Scan()">
<Div>Source: 
<input size=50 type=text value="c:\" id=path name=path class="Field" >
<div id=outPut_c></div>
</div>

</body>
</html>

Open in new window


SCRIPT
var Fo =new ActiveXObject("Scripting.FileSystemObject");
var StrOut = new String();
var FileName = new String();
var Extention = new String();
var FilePath = 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){
			if (FSo.item().Attributes & 2 ){}
			else{
				StrOut += "<tr "+ ((i%2)? "":"bgcolor=#FFFFFF")  +"><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()
{
	if(path.value.length>0 && Fo.FolderExists(path.value)){
		StrOut = "<table border=0 width=100% cellspacing=0>"
		FindFile(Fo.GetFolder(path.value));
		outPut_c.innerHTML = StrOut+"</table>";
		}
	else alert("Insert Correct Path Address");
}

Open in new window


Is it possible to call multiple folder contents and display in a webpage as it would seem the
outPut_c.innerHTML 

Open in new window

will only overwrite the existing display.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Obviously, if there is a better way to display mutliple folder content in a webpage, where the user can open the displayed folders\files.
- You might consider looking at a ready-to-run existing solution such as http://extplorer.sourceforge.net/ (written in js and php)

- you need to work at the DOM-level, so that your js codes adds content to your page innerHTML
So
-- initialize outPut_c.innerHTML, eg
            outPut_c.innerHTML = "<h1>Listing of files and directories</h1><hr>";

-- change
            outPut_c.innerHTML = StrOut+"</table>";
to
            outPut_c.innerHTML += StrOut+"</table>";
Hi,

Where do you stand currently on the issue?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial