Directories() 공개 정적인 메소드

Assumes source directory exists. destination may or may not exist.
public static Directories ( string source, string destination, Arguments arguments ) : void
source string
destination string
arguments Arguments
리턴 void
예제 #1
0
        private void T(Folder source, Folder destination)
        {
            var entrypointDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var root = Path.Combine(entrypointDirectory, nameof(ContentSyncTests));

            if (Directory.Exists(root))
            {
                Directory.Delete(root, recursive: true);
            }

            Directory.CreateDirectory(root);

            source.CreateOnDisk(root);
            destination.CreateOnDisk(root);

            var sourcePath      = Path.Combine(root, source.Name);
            var destinationPath = Path.Combine(root, destination.Name);

            Sync.Directories(sourcePath, destinationPath, new Arguments(sourcePath, destinationPath));

            var actual = Folder.FromDisk(Path.Combine(root, destination.Name));

            var areIdentical = Folder.AreIdentical(source, actual);

            Assert.True(areIdentical);

            Directory.Delete(root, recursive: true);
        }
예제 #2
0
        private static void Main(string[] args)
        {
            string source      = null;
            string destination = null;

            if (args.Length == 2)
            {
                source      = args[0];
                destination = args[1];
            }
            else
            {
                PrintUsage();
                return;
            }

            if (Directory.Exists(source))
            {
                source = Path.GetFullPath(source);
                if (Directory.Exists(destination))
                {
                    destination = Path.GetFullPath(destination);
                }

                using (Log.MeasureTime("Total time"))
                {
                    Sync.Directories(source, destination);
                }

                Log.PrintFinalReport();

                return;
            }

            if (File.Exists(source) && Directory.Exists(destination))
            {
                Sync.Files(source, Path.Combine(destination, Path.GetFileName(source)));
                return;
            }

            if (File.Exists(source))
            {
                Sync.Files(source, destination);
                return;
            }

            Console.Error.WriteLine($"Cannot sync {source} to {destination}");
        }
예제 #3
0
        private static int Main(string[] args)
        {
            try
            {
                var arguments = new Arguments(args);
                if (arguments.Help || args.Length == 0)
                {
                    PrintUsage();
                    return(0);
                }

                if (!string.IsNullOrEmpty(arguments.Error))
                {
                    Log.WriteError("Invalid arguments:" + Environment.NewLine + arguments.Error + Environment.NewLine);
                    PrintUsage();
                    return(1);
                }

                string source      = arguments.Source;
                string destination = arguments.Destination;

                if (Directory.Exists(source))
                {
                    source = Path.GetFullPath(source);
                    if (Directory.Exists(destination))
                    {
                        destination = Path.GetFullPath(destination);
                    }

                    using (Log.MeasureTime("Total time"))
                    {
                        Sync.Directories(source, destination, arguments);
                    }

                    Log.PrintFinalReport();

                    return(0);
                }

                if (File.Exists(source))
                {
                    source = Path.GetFullPath(source);

                    if (Directory.Exists(destination))
                    {
                        destination = Path.GetFullPath(destination);
                        destination = Path.Combine(destination, Path.GetFileName(source));
                    }

                    if (File.Exists(destination))
                    {
                        destination = Path.GetFullPath(destination);
                    }

                    if (arguments.Pattern != "*")
                    {
                        Log.WriteError($"The pattern cannot be specified when processing a single file.");
                        return(4);
                    }

                    Sync.Files(source, destination, arguments);
                    return(0);
                }

                Log.WriteError($"Cannot find file or directory: {source}");
                return(2);
            }
            catch (Exception ex)
            {
                Log.WriteError($"Unrecoverable error: {ex.Message}");
                return(3);
            }
        }