一个老问题,但是总有人爱问,遍历一个文件夹下的所有文件,并输出文件信息。
using System; using System.Collections.Generic; using System.ComponentModel;using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace IOTest { public partial class Form1 : Form { private FolderBrowserDialog fbd; public Form1() { fbd = new FolderBrowserDialog(); InitializeComponent(); } private void btnOpen_Click(object sender, EventArgs e) { //选择路径 fbd.ShowDialog(); this.richTextBox1.Text ="open:"+ fbd.SelectedPath; //输出文件名 PutOutName(fbd.SelectedPath); } private void PutOutName(string path) { foreach (string subPath in Directory.GetDirectories(path)) { PutOutName(subPath); } DirectoryInfo dir = new DirectoryInfo(path); foreach (FileInfo file in dir.GetFiles()) { this.richTextBox1.AppendText("\n"+file.FullName+" size:"+file.Length.ToString()+" createTime:"+file.CreationTime.ToString()); } } } }
时间: 2024-10-02 15:21:54