Skip to content

Instantly share code, notes, and snippets.

@Cazzar
Last active August 29, 2015 14:16
Show Gist options
  • Save Cazzar/547f4fa9e26daf6169d1 to your computer and use it in GitHub Desktop.
Save Cazzar/547f4fa9e26daf6169d1 to your computer and use it in GitHub Desktop.
So, I couldn't find a decent UTF-8 NFC normalizer. So I made one.
using System;
using System.IO;
using System.Text;
namespace FileNormalizer
{
class Program
{
static void Main(string[] args)
{
var arg = (args.Length > 0) ? args[0] : @"E:\Users\Cayde\Music";
Normalize(new DirectoryInfo(arg));
Console.WriteLine("Done!");
Console.ReadLine();
}
private static void Normalize(DirectoryInfo di)
{
foreach (var fi in di.GetFiles())
{
var name = fi.Name;
var norm = name.Normalize(NormalizationForm.FormC);
if (name == norm) continue;
Console.WriteLine("{0} is not normalized, fixing", norm);
File.Move(fi.FullName, Path.Combine(fi.DirectoryName, norm));
}
foreach (var d2 in di.GetDirectories())
{
var name = d2.Name;
var norm = name.Normalize(NormalizationForm.FormC);
if (name != norm)
{
Console.WriteLine("{0} is not normalized, fixing", norm);
File.Move(d2.FullName, Path.Combine(d2.Parent.FullName, norm));
}
Normalize(d2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment