提取文件夹内的文件名字
private void button6_Click(object sender, EventArgs e)
{
string folderPath = textBox4.Text.Trim();
if (!Directory.Exists(folderPath))
{
MessageBox.Show("指定的文件夹路径不存在!");
return;
}
string[] files = Directory.GetFiles(folderPath);
if (files.Length == 0)
{
MessageBox.Show("文件夹中没有文件!");
return;
}
string outputPath = Path.Combine(folderPath, "output.txt");
using (StreamWriter writer = new StreamWriter(outputPath))
{
foreach (string filePath in files)
{
string fileName = Path.GetFileName(filePath);
writer.WriteLine(fileName);
}
}
MessageBox.Show("已生成 TXT 文档!");
}