修改文件夹下所有文件并保存-创新互联

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.IsolatedStorage;
using System.Text;
using System.Text.RegularExpressions;
namespace 更改文件名
{
    class Program
    {
         
       static void Main(string[] args)
        {
            string path = @"D:\Web";
            DirectoryInfo TheFolder = new DirectoryInfo(path);
            string txt="";
            foreach (FileInfo item in TheFolder.GetFiles())
            {
                string name = item.Name;
                string[] houzhui = name.Split('.');
                string readtxt;
                bool pp = false;
                if (houzhui.Count()==2)
                {
                    using (StreamReader sr=new StreamReader(path+"\\"+item.Name,Encoding.UTF8))
                    {
                        readtxt = sr.ReadToEnd();
                        string pattern = @"inherits=\W\S*, \w*\W";
                        string inherits;
                       
                        foreach (Match match in Regex.Matches(readtxt, pattern))
                        {
                            pp = true;
                            string inher = match.Value.Substring(10,match.Value.LastIndexOf('"')-10);
                            inherits = "Inherits=" + '"' + inher.Split(',')[0] + '"' + " CodeBehind="+'"'+item.Name+".cs"+'"';
                          txt= readtxt.Replace(match.Value,inherits);
                        }
                      
                    }
                    if (pp)
                    {
                        using (StreamWriter sw = new StreamWriter(path + "\\" + item.Name))
                        {
                            sw.Write(txt);
                        }
                    }
                    
                }
                else
                {
                     
                }
            }
        }
    }
}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。

创新互联秉承实现全网价值营销的理念,以专业定制企业官网,做网站、成都网站制作,微信平台小程序开发,网页设计制作,移动网站建设全网营销推广帮助传统企业实现“互联网+”转型升级专业定制企业官网,公司注重人才、技术和管理,汇聚了一批优秀的互联网技术人才,对客户都以感恩的心态奉献自己的专业和所长。
名称栏目:修改文件夹下所有文件并保存-创新互联
转载源于:http://lszwz.com/article/gohdo.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款