NewFileName.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSIncAReportApp._1_UI.OTSTemplateDesigner
  12. {
  13. public partial class NewFileName : Form
  14. {
  15. string folderPath = "";
  16. string PathName = "";
  17. public string ChangePathName = "";
  18. public NewFileName(string a_Route,string a_PathName)
  19. {
  20. folderPath = a_Route;
  21. PathName = a_PathName;
  22. ChangePathName = a_PathName;
  23. InitializeComponent();
  24. }
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27. // 获取文件夹中的所有文件信息
  28. FileInfo[] files = new DirectoryInfo(folderPath).GetFiles("*.xml", SearchOption.AllDirectories);
  29. // 遍历文件信息数组并打印出文件名
  30. foreach (FileInfo file in files)
  31. {
  32. if (file.Name == textBox1.Text + ".xml")
  33. {
  34. MessageBox.Show("名称重复!");
  35. return;
  36. }
  37. }
  38. ChangePathName = textBox1.Text + ".xml";
  39. this.Close();
  40. }
  41. private void NewFileName_Load(object sender, EventArgs e)
  42. {
  43. }
  44. }
  45. }