我正在尝试将二进制AFP文件附加到一个文件中。当我在下面使用我的代码时,相同的文件被写入三次,而不是我已经附加到一个文件的三个文件。为什么$ bytes的值不会改变? Get-Content未成功,不会导致AFP文件中的错误。
def draw(self, screen, count):
if count >0 and count <= 50:
pygame.draw.circle(screen, (255,255,0), (int(self.pos.x)+16, int(self.pos.y)+16), 16)
else:
if self.direction == Vector2D(1, 0):
pygame.draw.arc(screen, (255, 255, 0), (int(self.pos.x), int(self.pos.y), 32, 32),
0.7853981634, 5.4977871438, 16)
elif self.direction == Vector2D(-1, 0):
pygame.draw.arc(screen, (255, 255, 0), (int(self.pos.x), int(self.pos.y), 32, 32),
-2.356194490, 2.356194490, 16)
elif self.direction == Vector2D(0, -1):
pygame.draw.arc(screen, (255, 255, 0), (int(self.pos.x), int(self.pos.y), 32, 32),
2.3561944902, 7.0685834706, 16)
elif self.direction == Vector2D(0, 1):
pygame.draw.arc(screen, (255, 255, 0), (int(self.pos.x), int(self.pos.y), 32, 32),
-0.7853981634, 3.926990817, 16)
下面的脚本是在我更改后将$ bytes存储到$ data变量然后写出$ data。
$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)
}
我试图通过将三个文件中的每一个设置为变量然后将它们添加到$ 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)
答案 0 :(得分:2)
WriteAllBytes()
始终会创建一个新文件。你想追加。试试这个:
...
$bytes = @()
foreach($afpFile in $list) {
$bytes += [System.IO.File]::ReadAllBytes($afpFile)
}
[io.file]::WriteAllBytes("D:\User1\Desktop\AFPTest\Content.afp",$bytes)