標籤:des style blog http os io 檔案 for ar
1、問題描述:
由為知筆記匯出的檔案匯入Evernote的時候,有一些(建立的)HTML檔案以<mate>標籤開頭,查閱Evernote的log可知因此檔案不能被匯入。
責任無論歸於為知還是Evernote都不重要,總之幾百篇日誌不可能通過複製粘貼進行匯入。
2、工具解決問題:
批量將某一檔案夾內不合規範html檔案規格化。
3、介面
4、主要代碼
private void button2_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog1.SelectedPath); FileInfo[] files = dir.GetFiles("*.html"); for (int i = 0; i < files.Length; i++) { System.IO.StreamReader sr = new System.IO.StreamReader(files[i].DirectoryName+"\\"+files[i].ToString()); NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(sr.ReadToEnd()); try { sr.Dispose(); File.Delete(files[i].DirectoryName + "\\" + files[i].ToString()); using (StreamWriter sw = new StreamWriter(files[i].DirectoryName+"\\"+files[i].ToString(), false, System.Text.Encoding.GetEncoding("UTF-8"))) //儲存地址 { sw.WriteLine(doc.ToString()); sw.Flush(); sw.Close(); } } catch { } } Application.Exit(); } }
5、源碼:
環境:vs2008
組件:Nsoup.dll
http://app.yinxiang.com/shard/s12/sh/e4ef4bd5-703b-41ba-9603-6f5fbd2934b1/690319451be72d6897f434e485d45de7
C# 批量規範HTML工具