}
function tree(n) {
var id = new Array("bar","pad","<IMG src='http://www.webjx.com/htmldata/2005-08-02/images/midnodeline.gif'border=0 align='absmiddle'><IMG src='http://www.webjx.com/htmldata/2005-08-02/images/close.gif 'border=0 align='absmiddle'>","<IMG src='http://www.webjx.com/htmldata/2005-08-02/images/midclosedfolder.gif 'border=0 align='absmiddle'><IMG src='http://www.webjx.com/htmldata/2005-08-02/images/close.gif 'border=0 align='absmiddle'>","<IMG src='http://www.webjx.com/htmldata/2005-08-02/images/lastnodeline.gif'border=0 align='absmiddle'><IMG src='http://www.webjx.com/htmldata/2005-08-02/images/close.gif 'border=0 align='absmiddle'>");
if(n == 0) { // 初始設定變數
n = 1;
i = 0;
s = "";
}
s += "<table border=0 cellspacing=0 cellpadding=0 >";
for(;i<tree_ar.length-1;i++) {
var k = (n >= tree_ar[i+1][0])?0:1;
if(tree_ar[i][2]==false)
{
id[2]="<IMG src='http://www.webjx.com/htmldata/2005-08-02/images/lastnodeline.gif'border=0 align='absmiddle'><IMG src='http://www.webjx.com/htmldata/2005-08-02/images/close.gif 'border=0 align='absmiddle'>";
}
s += "<tr id='"+id[k]+"' value="+i+"><td >"+id[k+2]+"</td><td>"+tree_ar[i][1]+"</td></tr>"; // // 構造節點,注意這裡的自訂屬性value。作用是簡化構造節點的描述,共用參數數組資訊。
if(n > tree_ar[i+1][0]) { // 若期望層次大於當前層次,結束本層次返回上一層次。
s += "</td></tr></table>";
return tree_ar[i+1][0];
}
if(n < tree_ar[i+1][0]) { // 若期望層次小於當前層次,遞迴進入下一層次。
s += "<tr style='display:none' ><td ";
if(tree_ar[i][2]==true)
{ //如果有下個兄弟節點,則畫兄弟節點間的連線
s+="background='images/line.gif' border=0 align='absmiddle'";
}
s+="></td><td>";
var m = tree(tree_ar[++i][0]);
s += "</td></tr>";
if(m < n) { // 當遞迴傳回值小於當前層次期望值時,將產生連續的返回動作
s += "</table>";
return m;
}
}
}
s += "</table>";
return s;
}
</script>
String s = "";
File dir = new File(path);
if (dir != null && dir.isDirectory()) {
String absolutePath = dir.getAbsolutePath();
absolutePath = absolutePath.replaceAll("\\\\", "\\\\\\\\");//對'\'的處理,在JSP參數傳遞時'\'和空格會出現錯誤
absolutePath = absolutePath.replaceAll(" ", "@"); //對空格的處理 ,這時用'@'替代
s += "new Array(" + index + ",'<a href=fileList.jsp?path="
+ absolutePath + "\\\\ target=mainFrame>" + dir.getName()
+ "</a>'," + hasNexetBrother + "), ";
hasNexetBrother = false;
index++;
File[] dirs = dir.listFiles();
java.util.List list = new java.util.ArrayList();
for (int i = 0; i < dirs.length; i++) {
if (dirs[i].isDirectory()) {//去除檔案.得到資料夾清單
list.add(dirs[i]);
}
}
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1)
hasNexetBrother = true;
String dirpath = ((File) list.get(i)).getAbsolutePath();
s += showFileTree(dirpath);//對子檔案夾遞迴處理