using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespaceDelete { publicpartialclassMain : Form { publicMain() { InitializeComponent(); }
// 浏览 privatevoidbtnLL_Click(object sender, EventArgs e) { FolderBrowserDialog f = new FolderBrowserDialog(); if (f.ShowDialog() == DialogResult.OK) { String DirPath = f.SelectedPath; this.txtPath.Text = DirPath;//G:\新建文件夹 } }
static List<string> list = new List<string>();//定义list变量 public List<string> getPath(string path) { // 获取子目录 DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] fil = dir.GetFiles(); DirectoryInfo[] dii = dir.GetDirectories(); foreach (FileInfo f in fil) { list.Add(f.FullName);//添加文件的路径到列表 } //获取子文件夹内的文件列表,递归遍历 foreach (DirectoryInfo d in dii) { getPath(d.FullName); list.Add(d.FullName);//添加文件夹的路径到列表 }