求C#遍历EXE程序问题!!
请问用递归算法应该怎么写代码实现?
string[] ss=System.IO.Directory.GetDirectories(path);
foreach(string s in ss)
{
//do something
}
string[]ex=System.IO.Directory.GetFiles(path);
foreach(string e1 in ex)
{
string t=e1.Substring(path.Length);
if(t.ToLower().EndsWith( ".exe "))
{
}
}
------解决方案--------------------修改一下:
Trees(DirectoryInfo dinfo)
{
if (!dinfo.Exists) return;
if (dinfo == null) return;
string[] files = dinfo.GetFiles();
for (int i = 0; i < files.Length; i++) //遍历目录下所有文件
{
FileInfo file = new FileInfo(files[i]);
if (file != null)
{
if (file.Extension.ToLower() == ".exe ")
{
//Do something
}
}
string[] dirs = dinfo.GetDirectories();
for (int i = 0; i < dirs.Length; i++) //遍历目录下子目录
{
DirectoryInfo dirInfo = new DirectoryInfo(dirs[i]);
if (dirInfo != null)
{
Trees(dirInfo); //对子目录进行递归调用
}
}
}