找传奇、传世资源到传世资源站!

C# 批量重命名文件名 实例源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C# 批量重命名文件名 实例源码 C#语言基础-第1张using System;using System.Windows.Forms;using System.IO;namespace FileRename{ public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void btnOpenPath_Click(object sender, EventArgs e) { FolderBrowserDialog f1 = new FolderBrowserDialog(); if (f1.ShowDialog() == DialogResult.OK) { txtPath.Text = f1.SelectedPath; } } private void btnRename_Click(object sender, EventArgs e) { if (txtPath.Text != "") { if (txtNew.Text != "") { string strOldPart = txtOld.Text.Trim(); string strNewPart = txtNew.Text.Trim(); DateTime StartTime = DateTime.Now; try { DirectoryInfo di = new DirectoryInfo(txtPath.Text); FileInfo[] filelist = di.GetFiles("*.*"); string strFileFolder = txtPath.Text; int i = 0; int TotalFiles = 0; foreach (FileInfo fi in filelist) { string strOldFileName = fi.Name; string strNewFileName = fi.Name.Replace(strOldPart, strNewPart); string strNewFilePath = @strFileFolder "\\" strNewFileName; filelist[i].MoveTo(@strNewFilePath); TotalFiles = 1; lstFiles.Items.Add("文件名:" strOldFileName " 已重命名为 " strNewFileName ""); i = 1; } DateTime EndTime = DateTime.Now; TimeSpan ts = EndTime - StartTime; Text = ("总耗时:" ts.Hours "时" ts.Minutes "分" ts.Seconds "秒" ts.Milliseconds "毫秒"); } catch { MessageBox.Show("路径无效!"); } } else { MessageBox.Show("没有匹配字符"); } } else { MessageBox.Show("请先择择路径!"); } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复