C# 遍历文件夹下所有子文件夹的文件
DirectoryInfo theFolder = new DirectoryInfo(@"F:\a\");
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
//遍历文件夹
foreach (DirectoryInfo NextFolder in dirInfo)
{
// this.listBox1.Items.Add(NextFolder.Name);
FileInfo[] fileInfo = NextFolder.GetFiles();
foreach (FileInfo NextFile in fileInfo) //遍历文件
this.listBox2.Items.Add(NextFile.Name);
}
C# 遍历当前文件夹下的文件
string filePath = txtFilePath.Text.Trim();
DirectoryInfo theFolder = new DirectoryInfo(filePath);
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
FileInfo[] fileInfo = theFolder.GetFiles();
foreach (FileInfo NextFile in fileInfo) //遍历文件
{
MessageBox.Show(NextFile.Name);
}