Advertisement
Adytzu04

SGDecoder

Jul 2nd, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.38 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. namespace FileLogDecoder
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             string pathexec;
  13.             pathexec = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  14.             string foldercreatepath = pathexec + "\\Output";   //Folder Path
  15.             string filecreatepath = foldercreatepath + "\\Data.txt"; //File Path
  16.             string dirpath = pathexec + "\\";
  17.  
  18.             Directory.CreateDirectory(foldercreatepath);
  19.             using (StreamWriter sw = new StreamWriter(filecreatepath, true))
  20.             {
  21.                 try
  22.                 {
  23.                     string[] dirs = Directory.GetFiles(dirpath, "*.txt");
  24.                     Console.WriteLine("The number of text files in this directory is {0}.", dirs.Length);
  25.                     foreach (string dir in dirs)
  26.                     {
  27.                         Console.WriteLine(dir);
  28.  
  29.                         using (FileStream F = new FileStream(dir, FileMode.Open, FileAccess.Read))
  30.                         {
  31.                             try
  32.                             {
  33.                                 using (StreamReader sr = new StreamReader(dir))
  34.                                 {
  35.                                     string line;
  36.                                     StringBuilder sb = new StringBuilder();
  37.  
  38.                                     while ((line = sr.ReadLine()) != null)
  39.                                     {
  40.                                         line = line.Replace(" ", string.Empty);
  41.                                         if (!Char.IsLetterOrDigit(line[0]) && !Char.IsDigit(line[line.Length-1]))
  42.                                         {
  43.                                             int five = 0;
  44.                                             int times = 0;
  45.                                             StringBuilder word = new StringBuilder();
  46.                                             string word2 = String.Empty;
  47.                                             for (int j = 1; j < line.Length; j++)
  48.                                             {
  49.                                                 char x = line[j];
  50.                                                 if (char.IsLetterOrDigit(line[j]))
  51.                                                 {
  52.                                                     word.Append(line[j]);
  53.                                                     five++;
  54.                                                     if (five >= 5)
  55.                                                     {
  56.                                                         word2 = word.ToString();
  57.                                                         times++;
  58.                                                     }
  59.                                                        
  60.                                                 }
  61.                                                 else
  62.                                                 {
  63.                                                     five = 0;
  64.                                                     word.Clear();
  65.                                                 }
  66.  
  67.                                             }
  68.                                             if (times == 1)
  69.                                             {
  70.                                                 sb.Append(word2 + Environment.NewLine);
  71.                                             }
  72.                                         }
  73.                                     }
  74.                                     Console.WriteLine(sb);
  75.                                 }
  76.                             }
  77.                             catch (Exception e)
  78.                             {
  79.                                 Console.WriteLine("The file could not be read:");
  80.                                 Console.WriteLine(e.Message);
  81.                             }
  82.                         }
  83.  
  84.                         /* -------------------------- */
  85.                     }
  86.                 }
  87.                 catch (Exception e)
  88.                 {
  89.                     Console.WriteLine("The process failed: {0}", e.ToString());
  90.                 }
  91.  
  92.  
  93.                 sw.Close();
  94.                 Console.WriteLine("\nPress any key to exit!");
  95.                 Console.ReadKey();
  96.             } //File
  97.         }
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement