Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created May 22, 2019 11:30
Show Gist options
  • Save gonaumov/c5a6b186e5c2037cc7e35eaf4044ed21 to your computer and use it in GitHub Desktop.
Save gonaumov/c5a6b186e5c2037cc7e35eaf4044ed21 to your computer and use it in GitHub Desktop.
This is a power-shell script for converting subtitles file to UTF-8 with BOM
foreach($i in Get-ChildItem -Recurse) {
if ($i.PSIsContainer) {
continue
}
$dest = $i.Fullname.Replace($PWD, "converted_files")
if (!(Test-Path $(Split-Path $dest -Parent))) {
New-Item $(Split-Path $dest -Parent) -type Directory
}
$extn = [IO.Path]::GetExtension($i.Fullname)
if ($extn -ne ".srt" )
{
continue
}
try {
$content = [IO.File]::ReadAllText($i.Fullname, [Text.Utf8Encoding]::new($false, $true))
} catch [System.Text.DecoderFallbackException] {
# Fall back to Windows-1251
$content = [IO.File]::ReadAllText($i.Fullname, [Text.Encoding]::GetEncoding(1251))
}
$content | out-file -encoding utf8 -filepath $dest
}
Read-Host -Prompt "All Done! Press Enter to exit."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment