Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- namespace FileLogDecoder
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pathexec;
- pathexec = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- string foldercreatepath = pathexec + "\\Output"; //Folder Path
- string filecreatepath = foldercreatepath + "\\Data.txt"; //File Path
- string dirpath = pathexec + "\\";
- Directory.CreateDirectory(foldercreatepath);
- using (StreamWriter sw = new StreamWriter(filecreatepath, true))
- {
- try
- {
- string[] dirs = Directory.GetFiles(dirpath, "*.txt");
- Console.WriteLine("The number of text files in this directory is {0}.", dirs.Length);
- foreach (string dir in dirs)
- {
- Console.WriteLine(dir);
- using (FileStream F = new FileStream(dir, FileMode.Open, FileAccess.Read))
- {
- try
- {
- using (StreamReader sr = new StreamReader(dir))
- {
- string line;
- StringBuilder sb = new StringBuilder();
- while ((line = sr.ReadLine()) != null)
- {
- line = line.Replace(" ", string.Empty);
- if (!Char.IsLetterOrDigit(line[0]) && !Char.IsDigit(line[line.Length-1]))
- {
- int five = 0;
- int times = 0;
- StringBuilder word = new StringBuilder();
- string word2 = String.Empty;
- for (int j = 1; j < line.Length; j++)
- {
- char x = line[j];
- if (char.IsLetterOrDigit(line[j]))
- {
- word.Append(line[j]);
- five++;
- if (five >= 5)
- {
- word2 = word.ToString();
- times++;
- }
- }
- else
- {
- five = 0;
- word.Clear();
- }
- }
- if (times == 1)
- {
- sb.Append(word2 + Environment.NewLine);
- }
- }
- }
- Console.WriteLine(sb);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("The file could not be read:");
- Console.WriteLine(e.Message);
- }
- }
- /* -------------------------- */
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("The process failed: {0}", e.ToString());
- }
- sw.Close();
- Console.WriteLine("\nPress any key to exit!");
- Console.ReadKey();
- } //File
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement