Exemplo n.º 1
0
        private (string Target, string[] Files) ReplaceNames(ReplaceOptions options)
        {
            var(search, replace, ignoreCase, target) =
                (
                    options.Search,
                    options.Replace,
                    options.IgnoreCase,
                    options.Target
                );

            var type = options.GetTargetType();

            switch (type)
            {
            case TargetType.File:
                var file = RenameFile(target, search, replace, ignoreCase);
                return(file, new[] { file });

            case TargetType.Directory:
                return(RenameDirectoryRecursive(target, search, replace, ignoreCase));

            default:
                throw new NotSupportedException($"{type}");
            }
        }
Exemplo n.º 2
0
        public async Task Replace(ReplaceOptions options)
        {
            try
            {
                if (!options.Verbose)
                {
                    Console.SetOut(TextWriter.Null);
                }

                Console.WriteLine("Checking target '{0}'...", options.Target);
                var type = options.GetTargetType();
                if (!type.HasValue)
                {
                    Console.WriteLine("File or directory '{0}' not found!", options.Target);
                    return;
                }

                var(newTarget, files) = ReplaceNames(options);
                options.Target        = newTarget;

                await ReplaceContent(options, files);
            }
            finally
            {
                if (!options.Verbose)
                {
                    Console.Out.Close();
                }
            }
        }