Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Performance improvement splitting huge file
#4
2GB file split in about 3 seconds on my drive.

Code: (Select All)
_DEFINE A-Z AS _INTEGER64
PRINT "Creating file data"
'create a nice large temp file
a$ = "Hello World. I'm Testing Crap!"
FOR i = 1 TO 26
a$ = a$ + a$
NEXT


OPEN "test.txt" FOR BINARY AS #1
PRINT "Writing file data", LEN(a$)
PUT #1, , a$
CLOSE

infile$ = "test.txt" 'the file to read in and split
savefile$ = "split test" 'the name of the files to save to, without extension or index
Splitfiles = 11 'split it into 11 parts (or whatever you want)


OPEN infile$ FOR BINARY AS #1
SplitFileSize = _CEIL(LOF(1) / Splitfiles)
PRINT "Splitting file data", SplitFileSize



t## = TIMER
i = 0: p = 1
DO UNTIL EOF(1) OR p > LOF(1)
i = i + 1
IF p + SplitFileSize > LOF(1) THEN SplitFileSize = LOF(1) - SplitFileSize * (i - 1)
partialfile$ = SPACE$(SplitFileSize)
GET #1, , partialfile$
p = p + SplitFileSize
outfile$ = savefile$ + "(" + _TRIM$(STR$(i)) + ").split"
PRINT "Writing file: "; outfile$, LEN(partialfile$)
OPEN outfile$ FOR OUTPUT AS #2: CLOSE #2
OPEN outfile$ FOR BINARY AS #2
PUT #2, , partialfile$
CLOSE #2
IF i > 100 THEN Explode
LOOP
PRINT USING "Done in ###.### seconds."; TIMER - t##

SUB Explode
BEEP
BEEP
BEEP
PRINT "OMG!! WE just filled the drive with a ton of crap from a bad, endless split!!"
BEEP
BEEP
BEEP
PRINT "HELP!!"
BEEP
BEEP
BEEP
PRINT "HELP!!"
BEEP
BEEP
BEEP
PRINT "DELETE IT ALL!! HEEEEEELLLPPPP!!!"
BEEP
BEEP
BEEP
END
END SUB
Reply


Messages In This Thread
RE: Performance improvement splitting huge file - by SMcNeill - 10-21-2023, 03:01 PM



Users browsing this thread: 3 Guest(s)