VB realizes the split and recovery of large files, referring to AdoDb.Stream provides a process code

zhaozj2021-02-08  211

'VB Segment and restore large files, providing a reference ADODB.Stream process:' To quote Microsoft ActiveX Data Objects 2.5 Libary 'or Microsoft ActiveX Data Objects 2.6 LibaryPublic Sub StreamSplit (SourceFile As String, DestinationFile As String, ChunkSize As Long, optional BufferSize as Long = 64 # * 1024 #, optional ShowFinishMessage as Boolean) 'ChunkSize is BufferSize multiple Dim adoStreamS as New ADODB.StreamadoStreamS.Type = adTypeBinaryadoStreamS.OpenadoStreamS.LoadFromFile SourceFileDim lFileSize as LonglFileSize = adoStreamS.SizeDim i as LongDim adoStreamT as new ADODB.StreamadoStreamT.Type = adTypeBinaryDo While lFileSize> = ChunkSize * BufferSize adoStreamT.Open adoStreamT.Write adoStreamS.Read (ChunkSize * BufferSize) adoStreamT.SaveToFile DestinationFile & "." & Format (i, "000"), IIf (Len (Trim (Dir (DestinationFile & & Format (i, "000"))) ".")> 0, adSaveCreateOverWrite, adSaveCreateNotExist) adoStreamT.Close lFileSize = lFileSize - ChunkSize * BufferSize i = i 1LoopIf lFileSize> 0 Then adoStreamT. Open AdoStreamt .Write adoStreams.read (LfileSize) AdoTreamt.savetofile destinationfile & "& format (i," 000 "), IIF (Len (Trim (Dir (Dir (Dir (Dir (Dir (Dir (Dir (Dir (DIR (000"))) )> 0, adsavecreateoverwrite, adsavecreatenotexist) End IFIF ShowfinishMessage Then Msgbox "Finished!" End iFend Sub

Public Sub StreamRestore (SourceFile As String, DestinationFile As String, Chunks As Long, Optional BufferSize As Long = 64 # * 1024 #, Optional ShowFinishMessage As Boolean) Dim lFileSize As LongDim adoStreamT As New ADODB.StreamadoStreamT.Type = adTypeBinaryadoStreamT.OpenDim adoStreamS As new ADODB.StreamadoStreamS.Type = adTypeBinaryDim i As LongFor i = 0 To Chunks - "." 1 'Chunks blocks adoStreamS.Open adoStreamS.LoadFromFile SourceFile & & Format (i, "000") adoStreamT.Write adoStreamS.Read adoStreamS. Closext Iadostreamt.savetofile DestinationFile, IIF (Trim (Trim (Trim (Dir (Dir (Dir (Dir (Dir (DIR (DIR (DIR (DIR (DIR (DESTINATIONFILE)))> 0, AdsaveCreateOverWrite, Adsavecreatenotexist) If ShowFinishMessage Then MsgBox "Finished!" End IFEND SUB

'VB realizes the segmentation and recovery of big files, using traditional classic code read and writes binary data: public subfilesplit (SourceFile As String, Destination File As String, CHUNKSIZE AS Long, Optional Buffize As long = 64 # * 1024 #, Optional ShowfinishMessage AS boolean) 'ChunkSize is BufferSize multiple Dim FileBuffer () as ByteDim FileNumberS as LongDim FileNumberT as LongFileNumberS = FreeFileOpen SourceFile For Binary Access Read as #FileNumberSDim lFileLen as LonglFileLen = FileLen (SourceFile) FileNumberT = FreeFileDim i as LongDim j as LongReDim FileBuffer (1 To (BufferSize)) As ByteOpen DestinationFile & "." & Format (i, "000") For Binary Access Write As #FileNumberTDo While lFileLen> = BufferSize Get #FileNumberS,, FileBuffer If i = ChunkSize Then i = 0 j = j "." 1 Close #FileNumberT FileNumberT = FreeFile Open DestinationFile & & Format (j, "000") For Binary Access Write As #FileNumberT End If i = i 1 Put #FileNumberT,, FileBuffer lFileLen = lFileLen - BufferSizeLoopIf lFileLen> 0 THEN Redim FileBuffer (1 to LFI) leLen) As Byte Get #FileNumberS,, FileBuffer Put #FileNumberT,, FileBufferEnd IfClose #FileNumberTIf ShowFinishMessage Then MsgBox "Finished!" End IfEnd SubPublic Sub FileRestore (SourceFile As String, DestinationFile As String, Chunks As Long, Optional BufferSize As Long = 64 # * 1024 #, Optional ShowFinishMessage As Boolean) Dim FileBuffer () As ByteDim FileNumberS As LongDim FileNumberT As LongDim i As LongDim lFileLen As LongFileNumberT = FreeFileOpen DestinationFile For Binary Access Write As #FileNumberTFor i = 0 To Chunks - 1 FileNumberS = FreeFile Open SourceFile & "." &

转载请注明原文地址:https://www.9cbs.com/read-1103.html

New Post(0)