using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace GetFiles { class Program { static void Main(string[] args) { string path = @"C:\Users\pengshiyu\Desktop\source"; if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path); string[] folders = Directory.GetDirectories(path); Console.WriteLine("获取所有文件:"); foreach (string file in files) { Console.WriteLine(file); } Console.WriteLine("获取所有文件夹:"); foreach (string folder in folders) { Console.WriteLine(folder); } } else { Console.WriteLine("文件夹不存在!"); } Console.ReadKey(); } } }