Пример #1
0
        static void Main(string[] args)
        {
            string pathA = @"W:\OneDrive\music";
            string pathB = @"G:\music";

            var start = DateTime.Now;
            var dirA = new Dir(new System.IO.DirectoryInfo(pathA));
            var time = (DateTime.Now - start).TotalMilliseconds;

            Console.WriteLine("mainlisting: " + time + "ms");

            start = DateTime.Now;
            var dirB = new Dir(new System.IO.DirectoryInfo(pathB));
            time = (DateTime.Now - start).TotalMilliseconds;

            Console.WriteLine("backlisting: " + time + "ms");

            start = DateTime.Now;
            var diff = dirA.Missing(dirB);
            time = (DateTime.Now - start).TotalMilliseconds;

            Console.WriteLine("diff calc  : " + time + "ms");

            File.WriteAllLines("diff.txt", diff);
        }
Пример #2
0
        /// <summary>
        /// Looks for dirs and files that exist in the other directory but not in this. Files inside missing dirs are not listed.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public IEnumerable<string> Missing(Dir other)
        {
            // Iterate the other collection to find items unique to it.
            var missingFiles = other.Files.Where(a => !Files.Any(b => a.Name == b.Name));
            var missingDirs = other.SubDirs.Where(a => !SubDirs.Any(b => a.Name == b.Name));

            var output = missingFiles.Select(a => a.Path);
            output = output.Concat(missingDirs.Select(a => a.Path));

            // Iterate through this collection so the we can look for matches.
            foreach (Dir dir in SubDirs)
            {
                var match = other.SubDirs.FirstOrDefault(a => a.Name == dir.Name);
                if (null != match)
                {
                    // If the dir exists, look for missing subdirs recursively.
                    output = output.Concat(dir.Missing(match));
                }
            }

            return output;
        }