//convert all unicode files in this directory into //brahmi-font viewable files public void batchConverter() { Console.WriteLine("... Brahmi Lipi - batch mode..."); Console.ReadLine(); string startupPath = System.IO.Directory.GetCurrentDirectory(); int no = 0; string[] files = Directory.GetFiles(startupPath); foreach (string file in files) { if ((!file.EndsWith("txt"))) continue; string line = ""; int counting = 0; ImperialBrahmi IBrahmi = new ImperialBrahmi(); List<string> newtext = new List<string>(); StreamReader fileObject = new System.IO.StreamReader(file, Encoding.Default); while ((line = fileObject.ReadLine()) != null) { counting++; line = line.ToLower(); //make sure we handle uppercase and lowercase not as diacritics newtext.Add(IBrahmi.Replace(line)); //newtext.Add("<h4>" + replace(line) + "</h4>"); //newtext.Add(line); } no++; Console.WriteLine("converted " + no + " from " + files.Length); fileObject.Close(); string filename = file + ".converted"; StreamWriter tt = new StreamWriter(filename, false, Encoding.UTF8); foreach (string l in newtext) { tt.WriteLine(l); } tt.Flush(); tt.Close(); } }
private void convert(string path) { ImperialBrahmi IBrahmi = new ImperialBrahmi(); FileStream fs = new FileStream(path, FileMode.Open); StreamReader sr = new StreamReader(fs, System.Text.Encoding.Unicode); string source = sr.ReadToEnd(); string destination = IBrahmi.Replace(source.ToLower()); fs.Close(); sr.Close(); FileStream fss = new FileStream(path + ".bl.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fss, System.Text.Encoding.Unicode); sw.Write(destination); }