C#遍历计算机上所有的文件
class Program { static List<string> allFileName=new List<string>(); static void Main(string[] args) { string[] drives = Directory.GetLogicalDrives(); foreach (string drive in drives) { getAll(drive); } } static void getAll(string path) { DirectoryInfo sDir = new DirectoryInfo(path); try { FileInfo[] fileArray = sDir.GetFiles(); foreach (FileInfo file in fileArray) { allFileName.Add(file.FullName); } } catch(Exception e) { } try { DirectoryInfo[] subDirArray = sDir.GetDirectories(); foreach (DirectoryInfo subDir in subDirArray) { getAll(subDir.FullName); } } catch (Exception e) { } } }