Skip to content

Instantly share code, notes, and snippets.

@atruskie
Last active November 2, 2016 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atruskie/bf0afe30de38f9f3ad2246282b12e409 to your computer and use it in GitHub Desktop.
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
$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