vbscript - 如何在 VBscript 中使用 ADODB.stream 连接二进制文件?

标签 vbscript binaryfiles

我必须将 3 个二进制文件连接成一个,但在尝试时遇到错误。这是我的代码:

' This is a simple example of managing binary files in
' vbscript using the ADODB object
dim inStream,outStream
const adTypeText=2
const adTypeBinary=1

' We can create the scream object directly, it does not
' need to be built from a record set or anything like that
set inStream=WScript.CreateObject("ADODB.Stream")

' We call open on the stream with no arguments.  This makes
' the stream become an empty container which can be then
' used for what operations we want
inStream.Open
inStream.type=adTypeBinary

' Now we load a really BIG file.  This should show if the object
' reads the whole file at once or just attaches to the file on
' disk
' You must change this path to something on your computer!
inStream.LoadFromFile(Zip7sSFX)
dim buff1
buff1 = inStream.Read()
inStream.LoadFromFile(Config)
dim buff2 
buff2= inStream.Read()
inStream.LoadFromFile(PackName)
dim buff3 
buff3= inStream.Read()
' Copy the dat over to a stream for outputting
set outStream=WScript.CreateObject("ADODB.Stream")
outStream.Open
outStream.type=adTypeBinary

dim buff
buff=buff1 & buff2 & buff3

' Write out to a file
outStream.Write(buff)
' You must change this path to something on your computer!
outStream.SaveToFile(OutputFile)

outStream.Close()
inStream.Close()

End Sub

我做错了什么?它提示 buff 类型不匹配。

最佳答案

您不能将 buff& 连接,因为它们是 (byte())Variants,而是可以附加到输出流直接:

const adTypeText=2
const adTypeBinary=1

dim inStream, outStream

set inStream=WScript.CreateObject("ADODB.Stream")
set outStream=WScript.CreateObject("ADODB.Stream")

inStream.Open
inStream.type=adTypeBinary

outStream.Open
outStream.type=adTypeBinary

inStream.LoadFromFile(Zip7sSFX)
outStream.Write = inStream.Read()

inStream.LoadFromFile(Config)
outStream.Write = inStream.Read()

inStream.LoadFromFile(PackName)
outStream.Write = inStream.Read()

outStream.SaveToFile(OutputFile)

outStream.Close()
inStream.Close()

关于vbscript - 如何在 VBscript 中使用 ADODB.stream 连接二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6035576/

相关文章:

powershell - 在脚本中的MSMQ队列上设置权限

vbscript - Robocopy - 比较文件的修改日期?

javascript - 使用 FileSystemObject write() 写入二进制数据

python-3.x - 如何在 python3 中通过 http 传输二进制文件?

c++ - 二进制读取、reinterpret_cast 和字节顺序

javascript - 实现状态 - 何时将状态更改为离线

javascript - Windows Scripting Host 中的 FTP 文件?

visual-studio - 如何使用 Visual Studio Community (2019) 调试 vbscript

ios - 修改二进制保存游戏数据 (iPhone)

java - 具有自定义对象的二进制文件 I/O - Java