i am trying to append binary AFP files into one file. When I used my code below the same file gets written three times instead of the three files I have getting appended to one file. Why would the value of $bytes not change? Get-Content was unsuccessful without causing errors in the AFP file.
$dira = "D:\User1\Desktop\AFPTest\"
$list = get-childitem $dira -filter *.afp -recurse | % { $_.FullName } | Sort-Object
foreach($afpFile in $list){
$bytes = [System.IO.File]::ReadAllBytes($afpFile)
[io.file]::WriteAllBytes("D:\User1\Desktop\AFPTest\Content.afp",$bytes)
}
The script below is after I made a change to store the $bytes to a $data variable and then write out $data.
$dira = "D:\User1\Desktop\AFPTest\"
$list = get-childitem $dira -filter *.afp -recurse | % { $_.FullName } | Sort-Object -descending
foreach($afpFile in $list){
Write-Host $afpFile
$bytes = [System.IO.File]::ReadAllBytes($afpFile)
$data += $bytes
}
[io.file]::WriteAllBytes("D:\User1\Desktop\AFPTest\Content.afp",$bytes)
I attempted to combine them manually by setting each of the three files to a variable and then adding them to the $data array but the same issue happens of the repeated image. The code is below.
$dira = "D:\User1\Desktop\AFPTest\"
$list = get-childitem $dira -filter *.afp -recurse | % { $_.FullName } | Sort-Object
$file3 = [System.IO.File]::ReadAllBytes("D:\User1\Desktop\AFPTest\000001.afp")
$file2 = [System.IO.File]::ReadAllBytes("D:\User1\Desktop\AFPTest\000002.afp")
$file1 = [System.IO.File]::ReadAllBytes("D:\User1\Desktop\AFPTest\000003.afp")
$data = $file1 + $file2
[io.file]::WriteAllBytes("D:\User1\Desktop\AFPTest\AFP.afp",$data)