C#实现文件批量改名
发布日期:2008-06-13最近更新:2008-06-13来源:BHCODE作者:
|
以下是C#实现文件批量改名的代码:
private void GhangeNames(string filepath, string sfm, int k) { DirectoryInfo inf = new DirectoryInfo(filepath); FileInfo[] files = inf.GetFiles(); try { for (int i = 0; i < files.Length; i++) { listBox1.Items.Add(files[i].Name); listBox2.Items.Add(textBox2.Text + (k + i).ToString(sfm) + files[i].Name.Substring(files[i].Name.LastIndexOf('.'))); files[i].MoveTo(files[i].DirectoryName + @"" + textBox2.Text + (k + i).ToString(sfm) + files[i].Name.Substring(files[i].Name.LastIndexOf('.'))); } MessageBox.Show("文件名修改结束", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { } } |