本文介绍了如何在VBscript中使用ADODB.stream连接二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我必须将3个二进制文件合并为一个,但尝试时出现错误,这是我的代码
Hi guysi have to concatenate 3 binary file into one but i m getting an error while i try it here is my code
' 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类型不匹配
What im doing wrong it complain about buff type mismatch
谢谢你Jp
推荐答案
您不能将buff
与&
连接在一起,因为它们是(byte())Variants
,而是可以直接附加到输出流:
You cannot concatenate your buff
s with &
as they are (byte())Variants
, instead you can append to the output stream directly:
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中使用ADODB.stream连接二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!