Created
May 22, 2019 11:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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