您的位置:首页 > 编程语言 > Python开发

在Windows系统中,如何python脚本实现分割合并大二进制文件,方便上传

2011-04-01 17:23 1761 查看
"""
To split a file, type the following command
split.py [filename] [chunksize in mb]

To recover it back, type the following command
copy /b [filename].part.0+[filename].part.1+[filename].part.2 [filename]
"""

from sys import argv
import os

def split(filename, chunksize):
statinfo = os.stat(filename)
print "file size: %d(mb)" % (statinfo.st_size/(1024*1024))
with open(filename, "rb") as f:
index = 0
while True:
chunk = f.read(chunksize)
if(chunk):
fn = "%s.part.%d" % (filename, index)
index = index + 1
print "creating", fn
with open(fn, "wb") as fw:
fw.write(chunk)
else:
break

def main():
filename = argv[1]
chunksize =  int(argv[2]) * 1024 * 1024
print "file name:", filename
print "chunk size: %d(mb)" % (chunksize/(1024*1024))
split(filename, chunksize)

main()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: