遍历文件夹
private string GetFolderInfo(string path)
{
if(Directory.Exists(path)) //判断文件夹是否存在
{
if (Directory.GetFileSystemEntries(path).Length == 0) //判断是否有子文件夹
HttpContext.Current.Response.Write("Folder " + path + " is empty");
else
{
string[] subdirectoryEntries = Directory.GetDirectories(path);
foreach(string subdirectory in subdirectoryEntries) //遍历文家夹
{
string[] fileNames = Directory.GetFiles(subdirectory); //获取该文家夹下得所有文件
foreach(string file in fileNames) //遍历文件
{
HttpContext.Current.Response.Write(file+"<br>");
if(file.IndexOf(".jpg")>=0) //判断是否为xml文件
{
/*
* 处理遍历文件
* */
}
}
GetFolderInfo(subdirectory);
}
}
}
return "";
}
{
if(Directory.Exists(path)) //判断文件夹是否存在
{
if (Directory.GetFileSystemEntries(path).Length == 0) //判断是否有子文件夹
HttpContext.Current.Response.Write("Folder " + path + " is empty");
else
{
string[] subdirectoryEntries = Directory.GetDirectories(path);
foreach(string subdirectory in subdirectoryEntries) //遍历文家夹
{
string[] fileNames = Directory.GetFiles(subdirectory); //获取该文家夹下得所有文件
foreach(string file in fileNames) //遍历文件
{
HttpContext.Current.Response.Write(file+"<br>");
if(file.IndexOf(".jpg")>=0) //判断是否为xml文件
{
/*
* 处理遍历文件
* */
}
}
GetFolderInfo(subdirectory);
}
}
}
return "";
}