Skip to content

Instantly share code, notes, and snippets.

@ashumeow
Forked from lodejard/gist:4f1273b709244273e520
Last active August 29, 2015 14:12
Show Gist options
  • Save ashumeow/8bc0581d1bce3eabac98 to your computer and use it in GitHub Desktop.
Save ashumeow/8bc0581d1bce3eabac98 to your computer and use it in GitHub Desktop.
[Fact]
public void RemoveBom()
{
foreach (var file in new DirectoryInfo("..\\..").EnumerateFiles("*", SearchOption.AllDirectories))
{
try
{
var allBytes = File.ReadAllBytes(file.FullName);
var allText = File.ReadAllText(file.FullName);
if (allBytes.Length - allText.Length == 3 &&
allBytes[0] == 0xef &&
allBytes[1] == 0xbb &&
allBytes[2] == 0xbf)
{
Console.WriteLine("{0} {1}", file.FullName, file.Length);
File.WriteAllText(file.FullName, allText, Encoding.Default);
}
}
catch
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment