using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace vcsREPL { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //-----------------------------------------------------------------------// private void Form1_Load(object sender, EventArgs e) { toolStripComboBox1.Items.Add("*.html"); toolStripComboBox1.Items.Add("*.txt"); textBox3.Multiline = true; textBox3.Visible = false; label1.Text = "処理ファイル名"; label2.Text = "検索文字列"; label3.Text = "置換文字列"; } //-----------------------------------------------------------------------// private void toolStripButton1_Click(object sender, EventArgs e) { string dir=""; //検索フォルダ string fpat="*.html";//検索拡張子 folderBrowserDialog1.Description = "フォルダを選択してください"; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { dir = folderBrowserDialog1.SelectedPath; } toolStripStatusLabel1.Text = dir; fpat = toolStripComboBox1.Text;//検索拡張子指定 foreach (string fn in System.IO.Directory.GetFiles(dir, fpat)) { listBox1.Items.Add(fn); } } //-----------------------------------------------------------------------// private void toolStripButton2_Click(object sender, EventArgs e) { string strold="", strnew="",fname=""; int k, nfile; strold = textBox1.Text;//検索文字列 strnew = textBox2.Text;//置換文字列 nfile = listBox1.Items.Count - 1; for (k = 0; k <= nfile; k++) { fname = listBox1.Items[k].ToString(); textBox3.Text = System.IO.File.ReadAllText(fname, System.Text.Encoding.GetEncoding("shift-jis")); textBox3.Text = textBox3.Text.Replace(strold, strnew); System.IO.File.WriteAllText(fname, textBox3.Text, System.Text.Encoding.GetEncoding("shift-jis")); } MessageBox.Show("処理完了", "完了通知"); } //-----------------------------------------------------------------------// } }