//指定扩展名的文件
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
string path = txtFilePath.Text.Trim(); //路径
string kzm = txtFilehouzhui.Text.Trim();//"*.txt" //扩展名 List<string> list = new List<string>();
DirectoryInfo folder = new DirectoryInfo(path); //对象初始化 foreach (FileInfo file in folder.GetFiles(kzm))
{
// file.Name; //输出文件名+扩展名
textBox1.Text += " -- " + file.FullName + "\r\n"; //获取的全路径
list.Add(file.FullName); //添加全路径
}
}
var filename = "";
//去掉扩展名
if (file.FileName.LastIndexOf(".") != -1)
{
filename = file.FileName.Substring(0, file.FileName.LastIndexOf("."));
}
else
{
//申请文件名称
filename = file.FileName;
}