Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how read files greater 2gb

Status
Not open for further replies.

robertgenova

Programmer
Jan 24, 2008
4
IT
I suppose it's a old problem but I have not found a right solution.
Someone can help me for how reading files in VB6 greater than 2GB?
Some solution with API seems not working.
Thanks for all suggest
 
Do a search for file size and then only do bigger then 2GB.

I am not entirely sure how to do it in VB but this example from VBA will identify size. You should be able to modify it without big problems. Do something like if s > 2gb then

Sub ShowFolderSize(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filespec)
s = UCase(f.Name) & " uses " & f.size & " bytes."
MsgBox s, 0, "Folder Size Info"
End Sub

 
Um - I believe the question is not about how to identify a file that is >2Gb, it is how to read the contents ...

Unfortunately the VB native file handling functions are limited to 2Gb

You might want to check out the FileSystemObject library, although this has a number of other limitations (not least that - technically - it only handles text files)
 
here my solution with API, but is still stopped after 2GB because param used are "LONG" type: I copied from


Code:
Public Sub ReadFile_2GB(xfilename As String, xlenFile As Double, xlenRec As Double, xStartRecord As Double, xRec As String, xFineFile As Boolean)
' ATTENTION record 1 is with DStartRecord = 0, the second has DStartRecord = 1...
' take care how you call this function!!!

   Dim Temp As Variant
   Dim i As Long
   Dim Ilen As Double
   
   'xlenRec = record len + CR/FL
   
   If bFirstTime Then
      F.SeekAbsolute 0, 0 'STARTING FROM POSITION 0 OF THE FILE  (Seeks 2 bytes (0*2^32 + 2) = 1 character.
      '----F.SeekRelative -2       ' Seeks forward 1 character (inizio file)
      bFirstTime = False
   Else
      If xlenRec * DStartRecord < xlenFile Then
         'test!!!!
         If xlenRec * DStartRecord <= 2147483647 Then
            F.SeekAbsolute 0, xlenRec * DStartRecord  '  overflow with value = 2.147.483.647! because param is a LONG!!!!)
         Else
            'F.SeekRelative (xlenRec * DStartRecord) ' overflow with value = 2.147.483.647! because param is a LONG!!!!)
            F.SeekAbsolute 1, (xlenRec * DStartRecord) - 2147483647 ' overflow with value = 2.147.483.647! because param is a LONG!!!!)
         End If
      Else
         bEndFile = True
      End If
      '----F.SeekRelative (xlenRec / 2) + 2     ' Seeks   aggiunge crlf!!!!
   End If
   
   Temp = F.ReadBytes(xlenRec)

   Ilen = Len(Temp)
   xRec = ""
   
   'from unicode  to ASCCI
   For i = LBound(Temp) To UBound(Temp)
       xRec = xRec & ChrW(Temp(i))
   Next
   
   xStartRecord = xStartRecord + 1
   
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top