As a practice I made a program that deletes all double lines in a file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
#region "processes "
static void Main(string[] args)
{
if (args.Length > 0)
{
for (int I = 0; I < args.Length; I++)
{
if (File.Exists(args[I]))
{
CheckFileLines(args[I]);
}
}
}
else
{
FileInvalid:
Console.WriteLine("Please Give Path to File To Check");
string Path = ConvertPath(Console.ReadLine());
if (!File.Exists(Path)) { goto FileInvalid; }
CheckFileLines(Path);
}
Console.ReadLine();
}
static void CheckFileLines(string Path)
{
List<string> TextLines = new List<string>();
List<string> LinesTNF = new List<string>();
StreamReader Reader;
Console.WriteLine(Path);
try
{
Reader = new StreamReader(File.OpenRead(Path));
while (!Reader.EndOfStream)
{
TextLines.Add(Reader.ReadLine());
}
Reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("");
Console.WriteLine(ex.Message);
}
for (int A = 0; A < TextLines.Count; A++)
{
bool isin = false;
for (int B = 0; B < LinesTNF.Count; B++)
{
if (LinesTNF[B] == TextLines[A]) { isin = true; }
}
if (!isin) { LinesTNF.Add(TextLines[A]); }
}
Console.WriteLine("Lines Deleted: " + (TextLines.Count - LinesTNF.Count).ToString());
File.WriteAllText(Path, string.Join(Environment.NewLine, LinesTNF.ToArray()));
}
#endregion
#region "Functions "
static string ConvertPath(string Path)
{
Path = Path.Replace("%DOCUMENTS%", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
return Path;
}
#endregion
}
}