C# 使用递归获取文件路径,不获取拒绝访问的文件夹
private string[] GetFiles(string path) { List<string> lstFiles = new List<string>(); lstFiles.AddRange(Directory.GetFiles(path)); string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { try { lstFiles.AddRange(GetFiles(dir)); } catch { continue; } } return lstFiles.ToArray(); }