c#遍历文件夹下所有文件并更改文件名

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.IsolatedStorage;
namespace 更改文件名
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"D:\vs2012\测试ierp\ierp-2\Web";
            DirectoryInfo TheFolder = new DirectoryInfo(path);
            foreach (FileInfo item in TheFolder.GetFiles())
            {
                string name = item.Name;
                if (name.Contains("_"))
                {
                   string xnm= name.Replace("_","-");
                   string xingname = path + "\\转换后的文件\\" + xnm;
                   item.MoveTo(xingname);
                }
                else
                {
                    string xingname = path + "\\转换后的文件\\" + name;
                    item.MoveTo(xingname);
                }
            }
        }
    }
}

文章标题:c#遍历文件夹下所有文件并更改文件名
标题网址:http://www.hxwzsj.com/article/ieidsj.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 营销网站建设 定制网站设计 外贸网站建设 重庆企业网站建设 网站建设公司 四川成都网站建设 自适应网站设计 成都网站制作 成都定制网站建设 营销型网站建设 专业网站设计 成都网站建设 网站建设公司 企业网站设计 网站设计公司 成都网站建设 网站建设方案 成都网站制作 成都网站建设 成都网站建设 成都网站建设 成都网站建设公司