Chop Shop File Splitter
Slice up Large Files into Smaller Chunks
Keywords: file splitter
Question:
I am trying to write a program to slice up large files into smaller chunks for copying to
floppy, emailing and the like. How to I do this?
Answer:
This sample code will prompt for a file and then
chop it up into smaller pieces that can fit on
a diskette. It also creates a BAT file that can
glue the pieces back together once they are
copies to the target machine.
; file splitter
splitsize=1400000
fn=AskFileName("Choose a file","","All|*.*|","",1)
fr=strcat(FilePath(fn),FileRoot(fn),".x")
fs=FileSize(fn)
dcount=int(fs/splitsize)
if (dcount*splitsize) < fs then dcount=dcount+1
Pause("ChopShop",strcat(fn,@crlf,"will be split into ",dcount," parts",@crlf,"of %splitsize% each",@crlf,"Do you want to continue."))
BoxOpen("ChopShop",strcat("Reading Source File",@crlf,fn))
fi=fs
fb=BinaryAlloc(fs)
fw=BinaryAlloc(splitsize)
BinaryRead(fb,fn)
index=0
while fi>0
frx=strcat(fr,index+10)
BoxText(strcat("Writing chopped file ",index+1,"/",dcount,@crlf,frx))
start=index*splitsize
count=splitsize
if count>fi then count=fi
BinaryEODSet(fw,0)
BinaryCopy(fw,0,fb,start,count)
BinaryWrite(fw,frx)
index=index+1
fi=fi-count
end while
if fi!=0 then Message("Ooopsie","fi is %fi%")
BinaryFree(fb)
BinaryFree(fw)
frbat=strcat(FilePath(fn),FileRoot(fn),".bat")
BoxText(strcat("Writing BAT file to rebuild source file",@crlf,frbat))
hh=FileOpen(frbat,"write")
ff=FileRoot(fn)
line="copy /b %ff%.x10"
for xx=2 to dcount
yy=xx+9
line=strcat(line,"+",ff,".x",yy)
next
line=strcat(line," ",FileRoot(fn),".",FileExtension(fn))
FileWrite(hh,line)
FileClose(hh)
Message("All","Doned")
Article ID: W13768
Filename: ChopShop File Splitter (Chop Files into Smaller Chunks).txt