ADODB.Stream
これにはオブジェクトを使用できます。
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 'binary
stream.LoadFromFile "doc1.txt"
chunk = stream.Read(512000)
stream.Close
stream.Open
stream.Type = 1 'binary
stream.Write chunk
stream.SaveToFile "dup1.txt", 2
stream.Close
Stream
入力ファイルは、次のように 2 つのオブジェクトを使用して複数のチャンクに分割できます。
Set iStream = CreateObject("ADODB.Stream")
Set oStream = CreateObject("ADODB.Stream")
iStream.Open
iStream.Type = 1 'binary
iStream.LoadFromFile "doc1.txt"
oStream.Open
oStream.Type = 1 'binary
oStream.Write iStream.Read(512000)
oStream.SaveToFile "dup.txt", 2
oStream.Close
oStream.Open
oStream.Type = 1 'binary
oStream.Write iStream.Read(512000)
oStream.SaveToFile "dup1.txt", 2
oStream.Close
oStream.Open
oStream.Type = 1 'binary
oStream.Write iStream.Read(512000)
oStream.SaveToFile "dup2.txt", 2
oStream.Close
...
iStream.Close
これは、プロシージャまたは関数で繰り返しコード セグメントをラップすることで簡略化できます。
Const chunksize = 512000
Sub WriteChunk(data, filename)
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1 'binary
oStream.Write data
oStream.SaveToFile filename, 2
oStream.Close
End Sub
Set iStream = CreateObject("ADODB.Stream")
iStream.Open
iStream.Type = 1 'binary
iStream.LoadFromFile "doc1.txt"
WriteChunk iStream.Read(chunksize), "dup.txt"
WriteChunk iStream.Read(chunksize), "dup1.txt"
WriteChunk iStream.Read(chunksize), "dup2.txt"
...
iStream.Close