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#遍历文件夹下所有文件并更改文件名
URL链接:http://hxwzsj.com/article/ieidsj.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 高端网站建设 重庆网站建设 商城网站建设 成都网站建设 古蔺网站建设 定制级高端网站建设 网站制作 手机网站制作设计 成都网站设计 网站设计制作报价 成都网站建设流程 成都网站制作 阿坝网站设计 高端网站设计 专业网站设计 网站建设公司 成都网站设计公司 重庆手机网站建设 成都响应式网站建设 成都营销网站制作 成都网站制作 成都网站建设