首页 >> 文档 >> C#专题

C# 批量改文件名

发布日期:2008-07-10最近更新:2008-07-10来源: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
            {
            }
        }

本周推荐
MORE
热点关注
MORE