How to add contents of a.bin to b.bin in Powershell?

How to add contents of a.bin file to b.bin file in Powershell?

+2


a source to share


2 answers


Maybe someone has a simpler approach, but this works:



[byte[]]$bytes = Get-Content a.bin -Encoding byte
Add-Content b.bin $bytes -Encoding byte

      

+1


a source


If that doesn't work, there is always an approach like this:



function AppendFile([string]$Source, [string]$Target)
{
    $TargetStream = [System.IO.File]::OpenWrite($Target);
    $SourceStream = [System.IO.File]::OpenRead($Source);

    $Buffer = New-Object Byte[] 8192;

    $TargetStream.Seek(0, [System.IO.SeekOrigin]::End);

    while (($BytesRead = $SourceStream.Read($Buffer, 0, $Buffer.Length)) -gt 0)
    {
        $TargetStream.Write($Buffer, 0, $BytesRead);
    }

    $TargetStream.Close();
    $SourceStream.Close();
}

      

0


a source







All Articles