Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Filtering
- {
- class Program
- {
- public List<string> items = new List<string>();
- static void Main(string[] args)
- {
- Console.Title = "Filter";
- Program c = new Program();
- c.setup();
- }
- public void setup()
- {
- this.write("Type filename to filter\nExample: proxys.txt");
- string filename = Directory.GetCurrentDirectory().ToString() +@"\" +Console.ReadLine(); //we set the name of the file that we want to filter.
- this.filter(filename);
- }
- public void filter(string filename)
- {
- try
- {
- using (StreamReader sr = File.OpenText(filename))
- {
- string lines = sr.ReadToEnd(); // we read all the lines of the file
- string[] line = lines.Split('\n'); // we parse all the lanes by new lines.
- foreach (string filtering in line)
- {
- if(!items.Contains(filtering))//we check if our list contains the lane,if not then add it to the list
- items.Add(filtering);
- }
- }
- this.write("File has been succesfully filtered");
- string randomfilename = randomString(); // we generate a random filename
- File.Create(randomfilename).Dispose();
- using (TextWriter tw = new StreamWriter(randomfilename))
- {
- for (int x = 0; x < this.items.Count; x++)
- {
- tw.WriteLine(this.items[x]); // we add all the lanes of the list to the new file
- }
- tw.Close();
- }
- this.write(string.Format("Everything is done! file has been saved as: {0}", randomfilename));
- Console.ReadLine();
- }
- catch
- {
- this.write(string.Format("Unable to find: {0}",filename));
- Console.ReadLine();
- }
- }
- public void write(string txt)
- {
- Console.WriteLine(string.Format("{0} -- {1}", DateTime.Now, txt));
- }
- public string randomString()
- {
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- var random = new Random();
- var result = new string(
- Enumerable.Repeat(chars, 8)
- .Select(s => s[random.Next(s.Length)])
- .ToArray());
- return result.ToString()+".txt";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement