Advertisement
5_2007-2008 Files/ File Controls/ Input/ Output #179337

Get a chunk from a file, but specify start and finish (usefull for splitting files / P2P program)

This code can be made to take a certain chunk of your choice from a file. Mainly for making resumable downloads etc, or working on a patch for a program... I made this cos im working on a file sharing program that downloads from multiple sources. SERVERAL UPDATES HAVE TAKEN PLACE (thanks to guys who posted comments improving the code)

AI

AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ソースコード
original-source
Option Explicit
Sub GetFilePart(FilenameFROM As String, FilenameTO As String, StartPos As Long, EndPos As Long)
 Dim bData() As Byte
 Dim sBuf As String
 Dim i As Long
 Dim l As Long
 Dim File1 as Integer
 Dim File2 as Integer
 
 File2 = Freefile
 Open FilenameTO For Binary As #File2
 File1 = Freefile
 Open FilenameFROM For Binary As #File1
 Get #File1, StartPos, bData
 
 ReDim bData(1 To 2048) As Byte
 
 For l = 1 To (EndPos - StartPos) \ 2048
 Get #File1, 2048 * (l - 1) + StartPos, bData
 Put #File2, , bData
 Next
 
 i = (EndPos - StartPos) Mod 2048
 If i <> 0 Then
 ReDim bData(1 To i) As Byte
 Get #File1, , bData
 Put #File2, , bData
 
 End If
 Close #File1
 
 Close #File2
End Sub
Private Sub cmdStart_Click()
 Call GetFilePart("c:\filename.exe", "C:\filename2.exe", 100, 3000)
 
 'this example above would get bytes 100 to 3000 in the program 'c:\filename.exe', and put them into
 'the file 'C:\filename2.exe'. The size of 'C:\filename2.exe' is now 2900 byes.
End Sub
オリジナルのコメント (3)
Wayback Machineから復元