Read large file in small bytes

Just starting out? Need help? Post your questions and find answers here.
Krisko
User
User
Posts: 22
Joined: Tue Jun 08, 2010 11:03 pm

Read large file in small bytes

Post by Krisko »

Hi all I'm wondering if I have a large file for example a file that is 5gb large. Can I read it and write it in small bytes (e.g. a byte that is 100mb large) and how can I make this ? Thank you :)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Read large file in small bytes

Post by ts-soft »

Split file?

Code: Select all

EnableExplicit

Define.s BigFile = "c:\my big file.dat"
Define.s SmallFiles = "c:\my smallfile_"

Define.i BF, SF, length, count = 1, bufSize = 100 * 1024 * 1024
Define *buf = AllocateMemory(bufSize)

BF = ReadFile(#PB_Any, BigFile)
If BF
  While Not Eof(BF)
    length = ReadData(BF, *buf, bufSize)
    If length
      SF = CreateFile(#PB_Any, SmallFiles + Str(count))
      count + 1
      If SF
        WriteData(SF, *buf, length)
        CloseFile(SF)
      EndIf
    EndIf
  Wend
  CloseFile(BF)
  FreeMemory(*buf)
EndIf
Krisko
User
User
Posts: 22
Joined: Tue Jun 08, 2010 11:03 pm

Re: Read large file in small bytes

Post by Krisko »

Oh thank you very much but how can I combine splited files back in one file after I separete them in parts :?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Read large file in small bytes

Post by ts-soft »

write the first file, the second and so on and close the new file :wink:
Krisko
User
User
Posts: 22
Joined: Tue Jun 08, 2010 11:03 pm

Re: Read large file in small bytes

Post by Krisko »

10x :)
Post Reply