惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News | PayPal Newsroom
Help Net Security
Help Net Security
The Hacker News
The Hacker News
H
Heimdal Security Blog
O
OpenAI News
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 叶小钗
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security Affairs
P
Proofpoint News Feed
S
Secure Thoughts
腾讯CDC
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客

博客园 - 星期六

C# winform授权:获取cpu和硬盘的序列号,得到机器码 获取主板及硬盘序列号 - 星期六 - 博客园 .net安装部署“Error 1001 在初始化安装时发生异常” 的解决方法 解决.net绘制的 WinForm 在 windows7下变形的方法。 如何使用 Visual C# 加密和解密文件 ppc通过蓝牙与电脑同步时无ActiveSync服务的解决方法。 winfrom中的几个界面皮肤控件 如何弹出一个模式窗口来显示进度条 .net 实现移动控件位置 如何在安装后自动运行程序? 调试自定义操作/安装程序类的方法 利用TimerCallback实现timer传递参数 网页中下载灰鸽子病毒的 SCRIPT 一段控制对象透明度的style. ASP.net 把 DataGrid 数据导出到 Excel . 用C#实现语音技术 ASP.NET 用读取二进制代码的方法在页面上显示指定图片。 c# 8条语句实现屏幕抓图 几条SQLl查询语句
批量替换文本文件中的字符
星期六 · 2010-08-10 · via 博客园 - 星期六

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.IO;
10 namespace ReplaceText
11 {
12     public partial class Form1 : Form
13     {
14         public Form1()
15         {
16             InitializeComponent();
17         }
18 
19         private void buttonRun_Click(object sender, EventArgs e)
20         {
21             int count = 0;
22             string patho = this.textBox1.Text;
23             string paths = this.textBox2.Text;
24             string newpath = "";
25             string log = "";
26             DirectoryInfo dir = new DirectoryInfo(patho);
27 
28             foreach (var f in dir.GetFiles("*.*", SearchOption.AllDirectories))
29             {
30                 if (this.ReadText(f.FullName).IndexOf(this.textBox3.Text) > -1)
31                 {
32                     count += 1;
33                     this.listBoxList.Items.Add(f.FullName);
34                     log += f.FullName + Environment.NewLine;
35                     newpath = f.FullName.Replace(this.textBox1.Text, this.textBox2.Text);
36                     Directory.CreateDirectory(Path.GetDirectoryName(newpath));
37                     File.Copy(f.FullName, newpath, true);
38                     Replace(newpath, this.textBox3.Text, this.textBox4.Text);
39                 }
40             }
41             this.labelMsg.Text = "替换了 " + count.ToString() + " 个文件";
42             log += this.labelMsg.Text;
43             using (StreamWriter sw = new StreamWriter("c:\\log.log"true, Encoding.GetEncoding("gb2312")))
44             {
45                 sw.Write(log);
46                 sw.Close();
47             }
48         }
49         private string ReadText(string path)
50         {
51             using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding("gb2312")))
52             {
53                 return sr.ReadToEnd();
54             }
55         }
56         private void Replace(string path, string oldValue, string newValue)
57         {
58             string text = this.ReadText(path);
59             text = text.Replace(oldValue, newValue);
60             File.Delete(path);
61             using (StreamWriter sw = new StreamWriter(path, true, Encoding.GetEncoding("gb2312")))
62             {
63                 sw.Write(text);
64                 sw.Close();
65             }
66         }
67     }
68 }
69