国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現的文件批量重命名功能示例

2020-01-24 00:35:41
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現的文件批量重命名功能。分享給大家供大家參考,具體如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;//C#批量重命名文件代碼的實現//添加文件操作空間引用using System.IO;namespace WindowsApplication1{  public partial class Form1 : Form  {    public Form1()    {      InitializeComponent();    }    private void Form1_Load(object sender, EventArgs e)    {    }    private void button1_Click(object sender, EventArgs e)    {      FolderBrowserDialog f1 = new FolderBrowserDialog();       if (f1.ShowDialog() == DialogResult.OK)      {        textBox3.Text = f1.SelectedPath;       }    }    private void button2_Click(object sender, EventArgs e)    {     if (textBox3.Text!=""){      if(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;//獲取開始時間       try{       DirectoryInfo di = new DirectoryInfo(textBox3.Text);       FileInfo[] filelist = di.GetFiles("*.*");       strFileFolder = textBox3.Text;       int i = 0;        foreach (FileInfo fi in filelist)        {          strOldFileName = fi.Name;          strNewFileName = fi.Name.Replace(strOldPart, strNewPart);          strNewFilePath = @strFileFolder + "http://" + strNewFileName;          filelist[i].MoveTo(@strNewFilePath);          TotalFiles += 1;          this.listBox1.Items.Add("文件名:" + strOldFileName + "  已重命名為 " + strNewFileName + "");          i += 1;      }      DateTime EndTime = DateTime.Now;//獲取結束時間      TimeSpan ts = EndTime - StartTime;      this.listBox1.Items.Add("總耗時:" + ts.Hours.ToString() + "時" + ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + "秒"+ ts.Milliseconds.ToString()+"毫秒");      }      catch      {      MessageBox.Show("路徑無效!");      }      }        else        {        MessageBox.Show("沒有匹配字符");        }      }      else      {        MessageBox.Show("請先擇擇路徑!");      }    }  }}

更多關于C#相關內容感興趣的讀者可查看本站專題:《C#文件操作常用技巧匯總》、《C#遍歷算法與技巧總結》、《C#程序設計之線程使用技巧總結》、《C#操作Excel技巧總結》、《C#中XML文件操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結》、《C#數據結構與算法教程》、《C#數組操作技巧總結》及《C#面向對象程序設計入門教程

希望本文所述對大家C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和田市| 浑源县| 牡丹江市| 自贡市| 电白县| 沂水县| 扎囊县| 阳西县| 保靖县| 红河县| 巴林左旗| 广宁县| 襄城县| 安化县| 灵宝市| 闸北区| 孟连| 当雄县| 雷山县| 万安县| 班玛县| 理塘县| 连云港市| 苏尼特左旗| 巫溪县| 兴隆县| 洞头县| 青州市| 临沂市| 进贤县| 商河县| 南靖县| 容城县| 扎囊县| 尉犁县| 兴文县| 马关县| 淳化县| 甘肃省| 米脂县| 绥江县|