使用c#如何批量重命名文件

  介绍

这篇文章将为大家详细讲解有关使用c#如何批量重命名文件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

具体如下:

使用c#如何批量重命名文件

using 系统;   using  System.Collections.Generic;   using  System.ComponentModel;   using  System.Data;   using  System.Drawing;   using 包含;   using  System.Windows.Forms;//c#批量重命名文件代码的实现//添加文件操作空间引用   using 先;   namespace  WindowsApplication1   {   public 才能;partial  class  Form1 :形式   {才能   ,,,public  Form1 ()   ,,,{   ,,,,,InitializeComponent ();   ,,,}   ,,,private  void  Form1_Load (object ,发送方,EventArgs  e)   ,,,{   ,,,}   ,,,private  void  button1_Click (object ,发送方,EventArgs  e)   ,,,{   ,,,,,FolderBrowserDialog  f1 =, new  FolderBrowserDialog ();   ,,,,,,if  (f1.ShowDialog (),==, DialogResult.OK)   ,,,,,{   ,,,,,,,textBox3.Text =, f1.SelectedPath;   ,,,,,,}   ,,,}   ,,,private  void  button2_Click (object ,发送方,EventArgs  e)   ,,,{   ,,,,if  (textBox3.Text !=啊? {   ,,,,,如果(textBox1.Text !=啊?   ,,,,,{   ,,,,,,string  strOldFileName;   ,,,,,,string  strNewFileName;   ,,,,,,string  strOldPart =, this.textBox1.Text.Trim ();   ,,,,,,string  strNewPart =, this.textBox2.Text.Trim ();   ,,,,,,string  strNewFilePath;   ,,,,,,string  strFileFolder;   ,,,,,,int  TotalFiles =, 0;   ,,,,,,DateTime  StartTime =, DateTime.Now;//获取开始时间   ,,,,,,试着{   ,,,,,,DirectoryInfo  di =, new  DirectoryInfo (textBox3.Text);   ,,,,,,FileInfo [], filelist =, di.GetFiles (“* . *“);   ,,,,,,strFileFolder =, textBox3.Text;   ,,,,,,int 小姐:=,0;   ,,,,,,,foreach  (FileInfo  fi 拷贝文件列表)   ,,,,,,,{   ,,,,,,,,,strOldFileName =, fi.Name;   ,,,,,,,,,strNewFileName =, fi.Name.Replace (strNewPart strOldPart也);   ,,,,,,,,,strNewFilePath =, @strFileFolder  +,“\ \”, +, strNewFileName;   ,,,,,,,,,文件列表[我].MoveTo (@strNewFilePath);   ,,,,,,,,,TotalFiles  +=, 1;   ,,,,,,,,,this.listBox1.Items.Add(“文件名:“,+,strOldFileName  +,,,,已重命名为,,,+,strNewFileName  +,““);   ,,,,,,,,,小姐:+=,1;   ,,,,,}   ,,,,,DateTime  EndTime =, DateTime.Now;//获取结束时间   ,,,,,TimeSpan  ts =, EndTime 作用;开始时间;   ,,,,,this.listBox1.Items.Add(“总耗时:“,+,ts.Hours.ToString(), +,“时“,+,ts.Minutes.ToString(), +,“分”,+,ts.Seconds.ToString(), +,“秒“+,ts.Milliseconds.ToString() +“毫秒“);   ,,,,,}   ,,,,,   ,,,,,{   ,,,,,MessageBox.Show(“路径无效!“);   ,,,,,}   ,,,,,}   ,,,,,,,   ,,,,,,,{   ,,,,,,,MessageBox.Show(“没有匹配字符“);   ,,,,,,,}   ,,,,,}   ,,,,,   ,,,,,{   null   null   null   null   null

使用c#如何批量重命名文件