Created
May 28, 2015 19:59
-
-
Save Koki-Shimizu/529e178e2e6ba9f3aa62 to your computer and use it in GitHub Desktop.
Revisions
-
Koki-Shimizu created this gist
May 28, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace fciv { class Program { static void Main(string[] args) { var files = Directory.GetFiles(@"C:\oracle\", "*.sql", SearchOption.AllDirectories).OrderBy(_ => _).ToList(); var outputXmlName = "result.xml"; File.Delete(outputXmlName); var sw = new Stopwatch(); sw.Start(); using( var outputXml = File.AppendText(outputXmlName) ) { foreach (var file in files) { var s = CheckSum(file, 4096); outputXml.WriteLine(s); } outputXml.Flush(); } sw.Stop(); var ts = sw.Elapsed; Debug.WriteLine(ts); // 出力例:00:00:00.9984668 } private static string CheckSum(string file, int bufferSize) { try { using (var sm = new BufferedStream(File.OpenRead(file), bufferSize)) { using( var sha = MD5.Create() ) { var checksum = sha.ComputeHash(sm); return BitConverter.ToString(checksum).Replace("-", String.Empty).ToLower(); } } } catch { // ファイルアクセス拒否時等… return string.Empty; } } } }