C#遍历文件夹下的所有文件

using System.IO;

DirectoryInfo di = new DirectoryInfo(strXmlFilePath);
FileInfo[] f = di.GetFiles("*.xml");//获取指定扩展名的文件

//没有xml文件
if (f.Length <= 0)
{
     return;
}

//遍历所有文件(*.xml)
foreach (FileInfo myFile in f)
{

}

//遍历所有文件夹

DirectoryInfo[] d = di.GetDirectories();

foreach(DirectoryInfo myDir in d)

{

    string str=myDir.FullName;

}

posted @ 2010-08-05 11:21  海乐学习  阅读(579)  评论(0编辑  收藏  举报