using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web
namespace PI_disease.PIAnalysis
{
/// <summary>
/// readfilename 的摘要说明
/// </summary>
public class readfilename : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//string FileName = "";
//string fileParent = "";
string strAll = "[";
//-----------------------------------------------------
//读取父节点名
string fileParent = getFileName();
string[] parentfile;
string strparent = "";
if (fileParent.Contains(',')) //父节点有多少个
parentfile = fileParent.Split(',');
else//就一个
{
strparent = fileParent;
parentfile = new string[1];
parentfile[0] = strparent;
}
for (int i = 0; i < parentfile.Length; i++)
{
string strparentfile = "{\"text\":\"" + parentfile[i] + "\",\"state\": \"closed\",\"children\":[";
strAll += strparentfile;
string strFile = "";
strFile = strFile + parentfile[i];
//-----------------------------------------------------
//读取第二级节点名
string secondfile = getFileName2(strFile);
string[] filename2;
string strsecond = "";
if (secondfile.Contains(',')) //文件名有多个
filename2 = secondfile.Split(',');
else//就一个
{
strsecond = secondfile;
filename2 = new string[1];
filename2[0] = strsecond;
}
for (int j = 0; j < filename2.Length; j++)
{
string strsecondfile = "{\"text\":\"" + filename2[j] + "\",\"state\": \"closed\",\"children\":[";
strAll += strsecondfile;
string strFile2 = "";
strFile2 = strFile2 + filename2[j];
//-----------------------------------------------------
//读取第三级节点名
string thirdfile = getFileName3(strFile, strFile2);
string[] filename3;
string strthird = "";
if (thirdfile.Contains(',')) //文件名有多个
filename3 = thirdfile.Split(',');
else//就一个
{
strthird = thirdfile;
filename3 = new string[1];
filename3[0] = strthird;
}
for (int k = 0; k < filename3.Length; k++)
{
string strthirdfile = "{\"text\":\"" + filename3[k] + "\"}";
if (k != filename3.Length - 1)
strAll += strthirdfile + ",";
else
strAll += strthirdfile;
}
strAll += "]}";
if (j != filename2.Length - 1)
strAll += ",";
}
strAll += "]}";
if (i != parentfile.Length - 1)
strAll += ",";
}
strAll += "]";
context.Response.Write(strAll);
}
private string getFileName()
{
string sfileName = "";
String path = @"X:\XX";
string[] aa = Directory.GetDirectories(path);
string[] FileName = new string[Directory.GetDirectories(path).Count()];
for (int i = 0; i < Directory.GetDirectories(path).Count(); i++)
{
FileName[i] = aa[i].Substring(path.Count() + 1);
}
for (int i = 0; i < FileName.Length; i++)
{
if (i != FileName.Length - 1)
sfileName = sfileName + FileName[i].ToString() + ",";
else
sfileName = sfileName + FileName[i].ToString();
}
return sfileName;
}
private string getFileName2(string strfile)
{
string sfileName = "";
String path = @"X:\XX\" + strfile + ""; //@"X:\XX\" 路径
string[] aa = Directory.GetDirectories(path);
string[] FileName = new string[Directory.GetDirectories(path).Count()];
for (int i = 0; i < Directory.GetDirectories(path).Count(); i++)
{
FileName[i] = aa[i].Substring(path.Count() + 1);
}
for (int i = 0; i < FileName.Length; i++)
{
if (i != FileName.Length - 1)
sfileName = sfileName + FileName[i].ToString() + ",";
else
sfileName = sfileName + FileName[i].ToString();
}
return sfileName;
}
private string getFileName3(string strfile, string strfile2)
{
string sfileName = "";
DirectoryInfo folder = new DirectoryInfo(@"X:\XX\" + strfile + "\\" + strfile2 + "");//文件夹名为Skins,放在软件根目录下
//循环文件夹下指定文件的信息
string[] FileName = new string[folder.GetFiles("*.jpg").Count()];
for (int i = 0; i < folder.GetFiles("*.jpg").Count(); i++)
{
//这里就是 给数组中指定索引来赋值了
FileName[i] = folder.GetFiles("*.jpg")[i].Name;
}
for (int i = 0; i < FileName.Length; i++)
{
if (i != FileName.Length - 1)
sfileName = sfileName + FileName[i].ToString() + ",";
else
sfileName = sfileName + FileName[i].ToString();
}
return sfileName;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}