如何连接使用ADODB.stream二进制文件在VBScript
问题描述:
嗨 我必须串联3二进制文件分割成一个,但IM得到一个错误,当我尝试这里是我的代码如何连接使用ADODB.stream二进制文件在VBScript
' 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
S作为他们(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()
不应该是'outStream.Write inStream.Read'吗? – Helen 2011-05-18 08:18:13
这样指定应该可以正常工作 – 2011-05-18 09:32:29
@Helen'Read()'是一个方法调用,我个人会这样写整行'调用outStream.Write(inStream.Read())'。 – Lankymart 2016-05-27 09:02:47