国利小工具,批量修改文件名
2012-02-22 15:45
190 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace CPN { public partial class Form1 : Form { protected int fCount = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) { this.textBox1.Text = this.folderBrowserDialog1.SelectedPath; } } private void button2_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(this.textBox1.Text.Trim())) { MessageBox.Show("对不起,路径存在错误!", "错误", MessageBoxButtons.OK); return; } DirectoryInfo dif = new DirectoryInfo(this.textBox1.Text.Trim()); if (!dif.Exists) { MessageBox.Show("对不起,路径存在错误!", "错误", MessageBoxButtons.OK); return; } else if (!string.IsNullOrEmpty(this.textBox3.Text.Trim())) { DirectoryInfo dif1 = new DirectoryInfo(this.textBox3.Text.Trim()); if (!dif1.Exists) { MessageBox.Show("对不起,路径存在错误!", "错误", MessageBoxButtons.OK); return; } } else if (string.IsNullOrEmpty(this.textBox2.Text.Trim())) { MessageBox.Show("对不起,项目名称不能为空!", "错误", MessageBoxButtons.OK); return; } else { fCount = 0; DealWithFile(this.textBox1.Text.Trim()); this.label5.Text = fCount.ToString(); } } catch(Exception ex) { MessageBox.Show(ex.Message.ToString(), "错误", MessageBoxButtons.OK); return; } } private void DealWithFile(string path) { DirectoryInfo dif = new DirectoryInfo(path); DirectoryInfo[] s_dif=dif.GetDirectories(); FileInfo[] s_fif = dif.GetFiles(); if (s_fif.Length > 0) { string fName = "", n_fName = ""; for (int i = 0; i < s_fif.Length; i++) { fName = s_fif[i].Name; if (fName.IndexOf("_") > 0) { //13711739184#_GDGLSA0012873853_20120111194045.wav //项目名_20120111194045_013711739184.wav string[] s_fName = fName.Replace("#", "").Substring(0, fName.Length - 5).Split('_'); n_fName = this.textBox2.Text.Trim() + "_" + s_fName[2] + "_" + s_fName[0] + ".wav"; if (string.IsNullOrEmpty(this.textBox3.Text.Trim())) { //原用文件上改 File.Move(s_fif[i].FullName, path + "\\" + n_fName); } else { if (!Directory.Exists(s_fif[i].DirectoryName.Replace(this.textBox1.Text.Trim(), this.textBox3.Text.Trim()))) Directory.CreateDirectory(s_fif[i].DirectoryName.Replace(this.textBox1.Text.Trim(), this.textBox3.Text.Trim())); File.Copy(s_fif[i].FullName, s_fif[i].DirectoryName.Replace(this.textBox1.Text.Trim(), this.textBox3.Text.Trim()) + "\\" + n_fName, true); } fCount += 1; } } } if (s_dif.Length > 0) { for (int i = 0; i < s_dif.Length; i++) { DealWithFile(path+"\\"+s_dif[i].Name); } } } private void button3_Click(object sender, EventArgs e) { if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) { this.textBox3.Text = this.folderBrowserDialog1.SelectedPath; } } } }
相关文章推荐
- 批量修改文件名工具
- C#代码反编译 得到项目可运行源码 经验分享(附:批量修改文件名工具)--摘抄
- C#代码反编译 得到项目可运行源码 经验分享(附:批量修改文件名工具)
- C#代码反编译 得到项目可运行源码 经验分享(附:批量修改文件名工具)
- C#代码反编译 得到项目可运行源码 经验分享(附:批量修改文件名工具)
- SubSonic - The Zero Code DAL (号称零代码的数据访问层开发工具)
- Java开发工具大全[14]
- 14个免费的网站访客行为分析工具
- 甘特图:项目管理控制工具 GanttProject
- 各种开发工具技巧小结
- 数据库开发工具DreamCoder 已完全免费
- MyEclipse工具
- Kvm管理工具之virsh
- linux 工具网站
- 工具系列-1
- eclipse内存分析工具MAT浅谈
- Linux内核源码阅读以及工具
- IE调试网页之三:使用 F12 工具控制台查看错误和状态 (Windows)
- 如何在putty终端上打开图形化管理工具
- [JavaScript]11个JavaScript工具web开发者不可错过