示例#1
0
        public static void FileNamesDiacriticsRemover(IEnumerable <string> dirs)
        {
            foreach (var directory in dirs)
            {
                var directories = Directory.GetDirectories(directory, "*", SearchOption.AllDirectories);
                foreach (var dir in directories.OrderByDescending(s => s.Length))
                {
                    var normalizedDir = Remover.RemoveDiacritics(dir);
                    if (dir == normalizedDir)
                    {
                        continue;
                    }

                    Directory.Move(dir, normalizedDir);
                    Log.Information($"Renaming {dir} -> {normalizedDir}");
                }

                directories = Directory.GetDirectories(directory, "*", SearchOption.AllDirectories);
                foreach (var dir in directories)
                {
                    FileNamesDiacriticsRemover(dir);
                }

                FileNamesDiacriticsRemover(directory);
            }
        }
示例#2
0
        public static void StdInDiacriticsRemover()
        {
            var line = Console.ReadLine();

            while (line != null)
            {
                Console.WriteLine(Remover.RemoveDiacritics(line));
                line = Console.ReadLine();
            }
        }
示例#3
0
        private static void FileNamesDiacriticsRemover(string dir)
        {
            var files = Directory.GetFiles(dir);

            foreach (var file in files)
            {
                var normalizedFile = Remover.RemoveDiacritics(file);
                if (file == normalizedFile)
                {
                    continue;
                }

                Directory.Move(file, normalizedFile);
                Log.Information($"Renaming {file} -> {normalizedFile}");
            }
        }
示例#4
0
        public static void ContentDiacriticsRemover(params string[] files)
        {
            foreach (var filePath in files)
            {
                if (!File.Exists(filePath))
                {
                    Log.Warning($"File: {filePath} does not exist...");
                    continue;
                }

                try
                {
                    var dirPath = Path.GetDirectoryName(filePath);
                    if (dirPath == null)
                    {
                        continue;
                    }

                    var fileName = Path.GetFileName(filePath);
                    if (fileName == null)
                    {
                        continue;
                    }

                    var strArray = File.ReadAllLines(filePath);
                    using (var streamWriter = new StreamWriter(Path.Combine(dirPath, "nodiacritics_" + fileName)))
                    {
                        foreach (var text in strArray)
                        {
                            streamWriter.WriteLine(Remover.RemoveDiacritics(text));
                        }
                    }

                    Log.Information($"Processed file {filePath}");
                }
                catch (IOException ex)
                {
                    Log.Error(ex, $"File {filePath} had IOException");
                }
            }
        }