here is the code, it prompts for the file name and the size of the block you want, then it split it for you.
Code: Select all
import os
file_name = raw_input("enter the full file name --> ")
block_size = int(raw_input("enter the block size in bytes --> "))
statinfo = os.stat(file_name)
number_of_blocks = statinfo.st_size/block_size
left_over = statinfo.st_size%block_size
fp = open(file_name,"rb")
for i in range(0,number_of_blocks):
block = fp.read(block_size)
binfile = open("bin.data."+str(i),"wb")
binfile.write(block)
binfile.close()
if left_over:
block = fp.read(left_over)
binfile = open("bin.data."+str(number_of_blocks),"wb")
binfile.write(block)
binfile.close()
fp.close()