//递归方法遍历目录,并统计其中文件的数目
private int statisticFiles(string directory)
{
int statistic=System.IO.Directory.GetFiles(directory).Length;
string[] directories = System.IO.Directory.GetDirectories(directory);
//深度遍历子目录
foreach (string dir in directories)
{
if (isDirectory(dir))
{
statistic += statisticFiles(dir);
}
else
{
MessageBox.Show("Directory is Inexistence.");
}
}
return statistic;
}
private static bool isDirectory(string p)
{
return System.IO.Directory.Exists(p);
}