There may be the requirement to show all the folders on the Client machine and Server side script will list folders of Application Server.
Html page: we have one Textbox to show and edit folder path.
Two buttons, one for getting the sub-folders and another one to go one level up
<input type=”text” id=”txtFolder” value=”c:\” style=”width:250px />
<input type=”button” value=”GetFolder”
onclick=”javascript:ShowFolderFileList(document.getElementById(‘txtFolder’).value);” />
<input type=”button” value=”Back” onclick=”javascript:back();” />
<ul id=”dvFolder”></ul>
Here is the Script:
<script type=”text/JScript”>
function ShowFolderList(folderspec)
{
var fso, f, fc, s=”;
fso = new ActiveXObject(“Scripting.FileSystemObject”);
folderspec = folderspec.replace(“%20”, ” “);
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.SubFolders);
if (fc.item() != undefined)
{
for (; !fc.atEnd(); fc.moveNext()) {
if (fc.item().Path.indexOf(‘$’) < 0) {
path = fc.item().Path.replace(/\\/g, “\\\\”).replace(” “,“%20”);
s += “<LI><a href=’#’ onclick=javascript:ShowFolderList(‘” + (path) + “‘);>” + path + “</a>”;
}
}
}
else
{
s=“No Folder Exists”
}
document.getElementById(“dvFolder”).innerHTML = s;
document.getElementById(‘txtFolder’).value = folderspec;
}
function back() {
ctrl = document.getElementById(“txtFolder”);
c = ctrl.value.split(‘\\’);
cval = ctrl.value.substring(0, ctrl.value.length – (c[c.length – 1].length + 1));
if (cval.substr(1, cval.length-1) == “:”)
cval = ctrl.value.substring(0, ctrl.value.length – (c[c.length – 1].length));
ctrl.value = cval;
ShowFolderList(ctrl.value);
}
The above code will show sub folders of the selected folder.