We help IT Professionals succeed at work.

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

313 Views
Last Modified: 2016-05-23
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

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.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
Hi,

Where do you stand currently on the issue?
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.