新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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://www.wjwzjz.com/article/ieidsj.html
在线咨询
服务热线
服务热线:028-86922220
TOP