如何才能遍历文件夹
我定义了一个方法ReadTextFile(string filename)
假设路径为c:\test 该目录下有多个xml文件,
请问如何才能遍历该文件夹下所有xml文件, 并且每查询到一个xml
文件就调用ReadTextFile(string filename)一次呢?
[解决办法]
directory dr = new directory( "c:\text ");
foreach(Fileinfo fi in dr.getfiles())
{
}
[解决办法]
public void ReadTextFile(string FilePath)
{
DirectoryInfo dirRoot = new DirectoryInfo(FilePath);
Console.WriteLine( "----Current Directory: " + FilePath + "--------------- ");
foreach(FileInfo file in dirRoot.GetFiles())
{
Console.WriteLine(file.DirectoryName);
}
foreach (DirectoryInfo direcory in dirRoot.GetDirectories())
{
ReadTextFile(direcory.FullName);
}
}