예제 #1
0
        private static IEnumerable <FileRecord> CopyOrNot(IList <FileRecord> records)
        {
            var groupedByDestination = records.OrderByDescending(x => x.SourcePath).GroupBy(x => x.DestinationPath);

            foreach (var group in groupedByDestination)
            {
                var groupedByChecksum = group.GroupBy(x => x.Checksum).ToList();
                if (groupedByChecksum.Count == 1)
                {
                    group.First().CopyOrNot = "copy";
                    foreach (var item in group.Skip(1))
                    {
                        item.CopyOrNot = "not";
                    }
                }
                else
                {
                    foreach (var item1 in groupedByChecksum)
                    {
                        var firstInGroup = item1.First();
                        var prefix       = firstInGroup.RelativePath.ToLower().Replace("/", "-").Replace("\\", "-");
                        firstInGroup.DestinationPath = FileRecordTools.CalculateDestinationPath(firstInGroup.Year, firstInGroup.Month,
                                                                                                $"{prefix}-{firstInGroup.Filename}");
                        firstInGroup.CopyOrNot = "copy";
                        foreach (var item2 in item1.Skip(1))
                        {
                            item2.CopyOrNot = "not";
                        }
                    }
                }
            }
            return(records);
        }
예제 #2
0
        private static IList <FileRecord> GetRecords(string src, string journal)
        {
            Console.WriteLine("Scanning files...");
            var records = FileRecordTools.GetFileRecords(src).ToList();

            Console.WriteLine("Processing result...");
            records = FindConflicts(FindDuplicates(records).ToList()).ToList();
            Console.WriteLine("Process copy or not...");
            records = CopyOrNot(records).ToList();

            Console.WriteLine("Exporting to excel...");
            ExportExcel(records, journal);

            Console.WriteLine("Generate stats for source directory");
            GenerateBasicStats(records);
            return(records);
        }
예제 #3
0
        static void CopyFilesFromSrcToDst(string src, string dst, string journalFilename, bool simulate)
        {
            var journal = Path.Combine(dst, journalFilename);

            Console.WriteLine("Removing old journal file..");
            if (File.Exists(journal))
            {
                File.Delete(journal);
            }

            var records = GetRecords(src, journal);

            if (simulate == false)
            {
                Console.WriteLine("Copying files");
                CopyFiles(records, dst);

                Console.WriteLine("Generate stats for destination directory");
                var recordsDst = FileRecordTools.GetFileRecords(dst).ToList();
                GenerateBasicStats(recordsDst);
            }
            System.Diagnostics.Process.Start("explorer", journal);
        }