def split(fromfile,todir,chunksize=chunksize):
if not os.path.exists(todir):
os.mkdir(todir)
else:
for fname in os.listdir(todir):
os.remove(os.path.join(todir,fname))
try:
parts = split(fromfile,todir,chunksize)
except:
print('Error during split:')
print(sys.exc_info()[0],sys.exc_info()[1])
else:
print('分割完成:',parts,'parts are in',absto)
--合并代码 start----
import sys,os
def joinfile(fromdir,filename,todir):
if not os.path.exists(todir):
os.mkdir(todir)
if not os.path.exists(fromdir):
print("合拼文件路径错误!")
outfile = open(os.path.join(todir,filename),"wb")
files = os.listdir(fromdir)
files.sort()
for file in files:
filepath = os.path.join(fromdir,file)
infile = open(filepath,"rb")
data = infile.read()
outfile.write(data)
infile.close()