I have to read a lot of files (like 500 or more, they are all text files; each file is little like 8 or 10 KB) in a directory.
Foreach file I have to open it, reading chars from 15 to 19, if chars are =="F24A0", i need to compute the has of the file and store it in a database. If !="F24A0" file will be skipped. What is the fastest way to do it? Any suggestion? I need a very fast way, cause i need to read a lot of files...
I made this: (pseudo code)
foreach (File file in Dir.GetFiles())
using (System.IO.FileStream fs = file.OpenRead()))
StreamReader sr = new StreamReader(fs);
char buff = new char;
fs.Position = 15;
sr.ReadBlock(buff, 0, 5);
fs.Position = 0;
string t = new String(buff);
System.Security.Cryptography.MD5 sscMD5 = System.Security.Cryptography.MD5.Create();
byte mHash = sscMD5.ComputeHash(fs);
retValue = Convert.ToBase64String(mHash); // diventa stringa da 24 caratteri!!!