c# 读取路径下文件夹名-文件夹名-文件名
2021-03-27 23:27
标签:sre 索引 tpc bst system str rdf 文件 oid using System; namespace PI_disease.PIAnalysis public void ProcessRequest(HttpContext context) string[] parentfile; for (int i = 0; i { string[] filename2; string[] filename3; for (int k = 0; k { if (k != filename3.Length - 1) private string getFileName() private string getFileName2(string strfile) private string getFileName3(string strfile, string strfile2) DirectoryInfo folder = new DirectoryInfo(@"X:\XX\" + strfile + "\\" + strfile2 + "");//文件夹名为Skins,放在软件根目录下 c# 读取路径下文件夹名-文件夹名-文件名 标签:sre 索引 tpc bst system str rdf 文件 oid 原文地址:https://www.cnblogs.com/jxy-94175/p/9345767.html
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web
{
///
/// readfilename 的摘要说明
///
public class readfilename : IHttpHandler
{
{
//string FileName = "";
//string fileParent = "";
string strAll = "[";
//-----------------------------------------------------
//读取父节点名
string fileParent = getFileName();
string strparent = "";
if (fileParent.Contains(‘,‘)) //父节点有多少个
parentfile = fileParent.Split(‘,‘);
else//就一个
{
strparent = fileParent;
parentfile = new string[1];
parentfile[0] = strparent;
}
string strparentfile = "{\"text\":\"" + parentfile[i] + "\",\"state\": \"closed\",\"children\":[";
strAll += strparentfile;
string strFile = "";
strFile = strFile + parentfile[i];
//-----------------------------------------------------
//读取第二级节点名
string secondfile = getFileName2(strFile);
string strsecond = "";
if (secondfile.Contains(‘,‘)) //文件名有多个
filename2 = secondfile.Split(‘,‘);
else//就一个
{
strsecond = secondfile;
filename2 = new string[1];
filename2[0] = strsecond;
}
for (int j = 0; j {
string strsecondfile = "{\"text\":\"" + filename2[j] + "\",\"state\": \"closed\",\"children\":[";
strAll += strsecondfile;
string strFile2 = "";
strFile2 = strFile2 + filename2[j];
//-----------------------------------------------------
//读取第三级节点名
string thirdfile = getFileName3(strFile, strFile2);
string strthird = "";
if (thirdfile.Contains(‘,‘)) //文件名有多个
filename3 = thirdfile.Split(‘,‘);
else//就一个
{
strthird = thirdfile;
filename3 = new string[1];
filename3[0] = strthird;
}
string strthirdfile = "{\"text\":\"" + filename3[k] + "\"}";
strAll += strthirdfile + ",";
else
strAll += strthirdfile;
}
strAll += "]}";
if (j != filename2.Length - 1)
strAll += ",";
}
strAll += "]}";
if (i != parentfile.Length - 1)
strAll += ",";
}
strAll += "]";
context.Response.Write(strAll);
}
{
string sfileName = "";
String path = @"X:\XX";
string[] aa = Directory.GetDirectories(path);
string[] FileName = new string[Directory.GetDirectories(path).Count()];
for (int i = 0; i {
FileName[i] = aa[i].Substring(path.Count() + 1);
}
for (int i = 0; i {
if (i != FileName.Length - 1)
sfileName = sfileName + FileName[i].ToString() + ",";
else
sfileName = sfileName + FileName[i].ToString();
}
return sfileName;
}
{
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 {
FileName[i] = aa[i].Substring(path.Count() + 1);
}
for (int i = 0; i {
if (i != FileName.Length - 1)
sfileName = sfileName + FileName[i].ToString() + ",";
else
sfileName = sfileName + FileName[i].ToString();
}
return sfileName;
}
{
string sfileName = "";
//循环文件夹下指定文件的信息
string[] FileName = new string[folder.GetFiles("*.jpg").Count()];
for (int i = 0; i {
//这里就是 给数组中指定索引来赋值了
FileName[i] = folder.GetFiles("*.jpg")[i].Name;
}
for (int i = 0; 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;
}
}
}
}
文章标题:c# 读取路径下文件夹名-文件夹名-文件名
文章链接:http://soscw.com/index.php/essay/68790.html