【发布时间】:2017-02-08 20:56:00
【问题描述】:
我正在尝试在经典 asp 中修复大量损坏的 .docx 文件。
(文件末尾缺少字节 - 详见this question)。
当我在 Sublime 中查看文件(以十六进制视图显示)时,可以通过在文件末尾添加 0000 来修复损坏。
但我正在努力以编程方式将这 4 个零添加到末尾。
我正在尝试使用cByteArray类,它的用法是这样的:
With oByte
Call .AddBytes(LoadBytes(sFilePath))
Call .AddBytes(HOW DO I GET THE BYTE VALUE OF 0000 HERE?)
lngBytes = .BytesTotal
ByteArray = .ReturnBytes
End With
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
我不知道如何将0000 值放入.AddBytes() 方法中。
我该怎么做?我有点超出我的深度,不确定我是否以正确的方式接近这一点。
在我的无知中,这是我尝试过的:
重新调整ByteArray 将多余的字节留空(因为我认为0000 代表空值)。
这似乎根本没有改变文件。新保存的文件与旧文件相同。
With oByte
Call .AddBytes(LoadBytes(sFilePath))
ByteArray = .ReturnBytes
End With
arrayLength = ubound(ByteArray)
redim ByteArray(arrayLength + 2)
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
将0000 从十六进制转换为字节并将其添加到损坏的文件字节中。
同样,这似乎根本没有改变文件。
dim k, hexString, str, stream, byteArrToAdd
hexString = "000000"
For k = 1 To Len(hexString) Step 2
str = str & Chr("&h" & Mid(hexString, k, 2))
response.write "<hr />" & str & "<hr />"
Next
Set stream = CreateObject("ADODB.Stream")
With stream
.Open
.Type = 2 ' set type "text"
.WriteText str
.Position = 0
.Type = 1 ' change type to "binary"
byteArrToAdd = .Read
.Close
End With
set stream = nothing
With oByte
Call .AddBytes(LoadBytes(sFilePath))
Call .AddBytes(byteArrToAdd)
ByteArray = .ReturnBytes
End With
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
获取损坏文件的最后一个字节,并在重新调整 ByteArray 后将其添加到 2 个新值中。
这似乎也根本没有改变文件!
With oByte
Call .AddBytes(LoadBytes(sFilePath))
ByteArray = .ReturnBytes
End With
arrayLength = ubound(ByteArray)
finalByte = ByteArray(arrayLength)
redim ByteArray(arrayLength + 2)
ByteArray(arrayLength + 1) = finalByte
ByteArray(arrayLength + 2) = finalByte
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
【问题讨论】:
-
您应该可以使用
ChrB()附加它们,类似Call .AddBytes(ChrB(&h00) & ChrB(&h00))应该可以工作。 -
我无法让它工作。
ControlChars.NullChar同上 - 既没有向文件添加任何字节。你觉得跟这个有关系吗? vbforums.com/…(很遗憾没有提供解决方案) -
对不起,伙计... 2017 年 11 月仍在使用经典 asp:/
标签: arrays asp-classic docx corruption