
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 + "\" + 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("请先择择路径!"); } } }}@H_404_0@更多关于C#相关内容感兴趣的读者可查看本站专题:《C#文件 *** 作常用技巧汇总》、《C#遍历算法与技巧总结》、《C#程序设计之线程使用技巧总结》、《C# *** 作Excel技巧总结》、《C#中XML文件 *** 作技巧汇总》、《C#常见控件用法教程》、《WinForm控件用法总结》、《C#数据结构与算法教程》、《C#数组 *** 作技巧总结》及《C#面向对象程序设计入门教程》@H_404_0@希望本文所述对大家C#程序设计有所帮助。 总结 以上是内存溢出为你收集整理的C#实现的文件批量重命名功能示例全部内容,希望文章能够帮你解决C#实现的文件批量重命名功能示例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)