16,554
社区成员
发帖
与我相关
我的任务
分享
#region 遍历指定目录
/// <summary>
/// 遍历指定目录
/// </summary>
/// <param name="path"></param>
private void getDirectories(string path)
{
try
{
string[] fileNames = Directory.GetFiles(path);
string[] directories = Directory.GetDirectories(path);
string tempstr = "";
foreach (string file in fileNames)
{
tempstr = file.Substring(file.LastIndexOf(@"\") + 1);
Console.WriteLine("Filename:{0} ", tempstr);
}
foreach (string dir in directories)
{
Console.WriteLine("Directoriesname:{0} ", dir);
getDirectories(dir);
}
}
catch (Exception ce)
{
throw (ce);
}
}
#endregion