'''
需求:给一个文件,按指定的大小切割成小文件。
设计:把源文件,切割好,存到一个文件夹中。
若文件夹存在,删除文件夹内所有东西;若文件夹不存在,者创建文件夹。。用到os.path.exists 方法;
文件切割在一个函数内,循环实现。
为了能让程序方便使用,对输入参数进行了设置。
分别对 切割的文件,存放的目录,切割的大小进行设置。
'''
import sys,os
kb = 1024
mb = kb * 1000
chunsize = int(mb*1.4)
def split(fromfile=None,todir=None,chunksize=chunsize):
if not os.path.exists(todir):
os.mkdir(todir)
else:
for fname in os.listdir(todir):
os.remove(os.path.join(todir,fname))
partnum = 0
input = open(fromfile,'rb')
while True:
chunk = input.read(chunksize)
if not chunk: break
partnum +=1
filename = os.path.join(todir,('part%04d'