Gatzi
Super Elite User
- Registriert
- 29. April 2014
- Beiträge
- 2.950
- Lösungen
- 1
- Reaktionspunkte
- 16.178
- Punkte
- 383
Hallo zusammen, schaut mal drauf und geb euere Meinung dazu ab ...
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ddr
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length != 2)
{
Program.ShowSyntax();
}
else
{
string str1 = args[0];
string path1 = args[1];
if (!Directory.Exists(str1))
Console.WriteLine(string.Format("Quellpfad: '{0}' nicht vorhanden", (object) str1));
else if (!Directory.Exists(path1))
{
Console.WriteLine(string.Format("Zielpfad: '{0}' nicht vorhanden", (object) path1));
}
else
{
IEnumerable<string> source = Directory.EnumerateFiles(str1);
Console.WriteLine(string.Format("{0} Datei(en) gefunden.", (object) source.Count<string>()));
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Console.WriteLine("");
foreach (string str2 in source)
{
string str3 = Path.Combine(path1, ((FileSystemInfo) new FileInfo(str2)).get_Name());
Console.Write(((FileSystemInfo) new FileInfo(str2)).get_Name());
StreamReader streamReader = File.OpenText(str2);
StreamWriter text = File.CreateText(str3);
Dictionary<int, string> dictionary = new Dictionary<int, string>();
int num = 0;
while (true)
{
string str4 = ((TextReader) streamReader).ReadLine();
if (str4 != null)
{
int hashCode = str4.Substring(20).GetHashCode();
if (!dictionary.ContainsKey(hashCode))
{
((TextWriter) text).WriteLine(str4);
dictionary.Add(hashCode, "");
}
if (num % 100000 == 0)
Console.Write(".");
++num;
}
else
break;
}
Console.WriteLine("Fertig");
((TextWriter) text).Flush();
((TextWriter) text).Close();
((TextReader) streamReader).Close();
File.Delete(str2);
}
stopwatch.Stop();
Console.WriteLine(string.Format("{0}s", (object) ((double) stopwatch.ElapsedMilliseconds / 1000.0)));
}
}
}
public static void ShowSyntax()
{
Console.WriteLine("Syntax: ddr [Quellpfad] [Zielpfad]");
}
public static void GenerateTestFile()
{
int num = 100;
Random random = new Random();
StringBuilder stringBuilder = new StringBuilder();
List<string> stringList = new List<string>();
StreamWriter text = File.CreateText(Path.Combine(Directory.GetCurrentDirectory(), "generate.txt"));
for (int index1 = 0; index1 < 4000000; ++index1)
{
for (int index2 = 0; index2 < num; ++index2)
stringBuilder.Append(random.Next(1, 9).ToString());
stringList.Add(stringBuilder.ToString());
stringBuilder.Clear();
}
for (int index = 0; index < 40000000; ++index)
{
((TextWriter) text).WriteLine(stringList[random.Next(0, 4000000)]);
if (index % 1000 == 0)
((TextWriter) text).Flush();
}
((TextWriter) text).Close();
}
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ddr
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length != 2)
{
Program.ShowSyntax();
}
else
{
string str1 = args[0];
string path1 = args[1];
if (!Directory.Exists(str1))
Console.WriteLine(string.Format("Quellpfad: '{0}' nicht vorhanden", (object) str1));
else if (!Directory.Exists(path1))
{
Console.WriteLine(string.Format("Zielpfad: '{0}' nicht vorhanden", (object) path1));
}
else
{
IEnumerable<string> source = Directory.EnumerateFiles(str1);
Console.WriteLine(string.Format("{0} Datei(en) gefunden.", (object) source.Count<string>()));
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Console.WriteLine("");
foreach (string str2 in source)
{
string str3 = Path.Combine(path1, ((FileSystemInfo) new FileInfo(str2)).get_Name());
Console.Write(((FileSystemInfo) new FileInfo(str2)).get_Name());
StreamReader streamReader = File.OpenText(str2);
StreamWriter text = File.CreateText(str3);
Dictionary<int, string> dictionary = new Dictionary<int, string>();
int num = 0;
while (true)
{
string str4 = ((TextReader) streamReader).ReadLine();
if (str4 != null)
{
int hashCode = str4.Substring(20).GetHashCode();
if (!dictionary.ContainsKey(hashCode))
{
((TextWriter) text).WriteLine(str4);
dictionary.Add(hashCode, "");
}
if (num % 100000 == 0)
Console.Write(".");
++num;
}
else
break;
}
Console.WriteLine("Fertig");
((TextWriter) text).Flush();
((TextWriter) text).Close();
((TextReader) streamReader).Close();
File.Delete(str2);
}
stopwatch.Stop();
Console.WriteLine(string.Format("{0}s", (object) ((double) stopwatch.ElapsedMilliseconds / 1000.0)));
}
}
}
public static void ShowSyntax()
{
Console.WriteLine("Syntax: ddr [Quellpfad] [Zielpfad]");
}
public static void GenerateTestFile()
{
int num = 100;
Random random = new Random();
StringBuilder stringBuilder = new StringBuilder();
List<string> stringList = new List<string>();
StreamWriter text = File.CreateText(Path.Combine(Directory.GetCurrentDirectory(), "generate.txt"));
for (int index1 = 0; index1 < 4000000; ++index1)
{
for (int index2 = 0; index2 < num; ++index2)
stringBuilder.Append(random.Next(1, 9).ToString());
stringList.Add(stringBuilder.ToString());
stringBuilder.Clear();
}
for (int index = 0; index < 40000000; ++index)
{
((TextWriter) text).WriteLine(stringList[random.Next(0, 4000000)]);
if (index % 1000 == 0)
((TextWriter) text).Flush();
}
((TextWriter) text).Close();
}
}
}