如何在Powershell中将a.bin的内容附加到b.bin?

时间:2010-05-08 16:09:40

标签: powershell

如何将文件a.bin的内容附加到Powershell中的文件b.bin?

2 个答案:

答案 0 :(得分:1)

也许某人有一个更简单的方法,但这有效:

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

答案 1 :(得分:0)

如果这不起作用,总会有这种方法:

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();
}