Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<FileInfo> files = new List<FileInfo>();
- public static void ListDrive(string drive)
- {
- try
- {
- DirectoryInfo di = new DirectoryInfo(drive);
- foreach (FileInfo fi in di.GetFiles())
- {
- files.Add(fi);
- }
- }
- catch (UnauthorizedAccessException)
- { }
- }
- //Find duplicates
- public static void ListDuplicates()
- {
- var duplicatedFiles = files.GroupBy(x => new { x.Length }).Where(t => t.Count() > 1).ToList();
- Console.WriteLine("Total items: {0}", files.Count);
- Console.WriteLine("Probably duplicates {0} ", duplicatedFiles.Count());
- StreamWriter duplicatesFoundLog = new StreamWriter("log.txt");
- foreach (var filter in duplicatedFiles)
- {
- duplicatesFoundLog.WriteLine("Probably duplicated item: Name: { 0}, Length: { 1}",
- filter.Key.Length);
- var items = files.Where(x => x.Length == filter.Key.Length).ToList();
- int c = 1;
- foreach (var suspected in items)
- {
- duplicatesFoundLog.WriteLine("{3},{ 0}- { 1}, Creation date { 2}",
- suspected.Name, suspected.FullName, suspected.CreationTime, c);
- c++;
- }
- duplicatesFoundLog.WriteLine();
- }
- duplicatesFoundLog.Flush();
- duplicatesFoundLog.Close();
- }
- try
- {
- Console.WriteLine("Enter the path");
- string path = Console.ReadLine();
- ListDrive(path);
- ListDuplicates();
- Console.ReadLine();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- Console.ReadLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement