Last active
November 2, 2016 07:18
-
-
Save atruskie/bf0afe30de38f9f3ad2246282b12e409 to your computer and use it in GitHub Desktop.
Dodgy ass (but pretty fast) powershell to strip a prefix of bytes from the front of the file, if the prefix is in the file
This file contains 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
$pattern = "<html>`n" | |
ls *.wav | %{ | |
echo ("Fixing" + $_.FullName) | |
if ([System.Text.Encoding]::ASCII.GetString((gc $_.FullName -Encoding Byte -TotalCount ($pattern.Length * 2))).StartsWith($pattern)) { | |
echo ("Reading" + $_.FullName) | |
$stream = $_.OpenRead() | |
$stream.Seek($pattern.Length, [System.IO.SeekOrigin]::Begin) | |
$destStream = [System.IO.File]::OpenWrite($_.FullName + ".trimmed.wav") | |
echo ("Writing" + $_.FullName) | |
$stream.CopyTo($destStream) | |
$destStream.Dispose() | |
$stream.Dispose() | |
} | |
echo ("Done" + $_.FullName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment