Skip to content

Instantly share code, notes, and snippets.

@iamleeky
Last active September 7, 2018 02:07
Show Gist options
  • Select an option

  • Save iamleeky/c76c3eb002b8b21c5df01bbb141cca3d to your computer and use it in GitHub Desktop.

Select an option

Save iamleeky/c76c3eb002b8b21c5df01bbb141cca3d to your computer and use it in GitHub Desktop.
Re-save as UTF-8 encoded files
######################################################################
# Script to re-save a file or all files recursively in a directory
# as URF-8 encoded file or files
#
# Author: iamleeky@gmail.com
######################################################################
# Target file or directory
$TargetPath = "C:\yourpath"
# Target name formats
$Filter = @("*.asp","*.asa")
# If you want to remove UTF8 signature - BOM (Byte Order Mark), then set it as $true
$RemoveBom = $false
Get-ChildItem $TargetPath -recurse -Include $Filter | ForEach-Object {
$content = $_ | Get-Content
Set-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force
if ($RemoveBom)
{
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllLines($_.Fullname, $content, $Utf8NoBomEncoding)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment