将分割的文件进行合并
来源:互联网 发布:excel表格数据求和为0 编辑:程序博客网 时间:2024/06/07 01:25
#!/usr/bin/env python3import os,sys,timereadsize=1024j='=' def join(fromdir,tofile): if os.path.exists(tofile): os.remove(os.path.join(fromdir,tofile)) output=open(tofile,'wb') parts=os.listdir(fromdir) parts.sort() pars=len(parts) i=0 for filename in parts: i+=1 filepath=os.path.join(fromdir,filename) fileobj=open(filepath,'rb') while True: filebytes=fileobj.read(readsize) if not filebytes: break output.write(filebytes) fileobj.close() perbar(i,pars) output.close() print('文件合并完成') def perbar(i,pars): global j sys.stdout.write('文件正在合并:||'+('%s'+'%'+str((138-len(j)))+'s')%(j,'['+str(int(i/pars*100))+']')+'\r') sys.stdout.flush() time.sleep(0.01) j += '=' if __name__=='__main__': if len(sys.argv) == 2 and sys.argv[1] == '-help': print('usage: join-file.py [from-dirname to-filename]') else: if len(sys.argv) != 3: interactive=True fromdir=input('请输入存储块的目录:') tofile=input('请输入合并后的文件名:') else: interactive = False fromdir,tofile=sys.argv[1:] absfrom,absto=map(os.path.abspath,[fromdir,tofile]) print('合并',absfrom,'到文件',absto) try: join(fromdir,absto) except: print('合并文件发生错误异常') print(sys.exc_info()[0],sys.exc_info()[1]) else: print('文件合并结果:',absto) if interactive: input('请输入enter键')
0 0
- 将分割的文件进行合并
- 黑马程序员——SequenceInputStream流将分割后的文件进行合并
- 合并分割的文件
- 使用Python进行文件的分割与合并
- Java-使用IO流对大文件进行分割和分割后的合并
- Java-使用IO流对大文件进行分割和分割后的合并
- 怎么将较大的PDF文件进行分割
- 将PDF文件进行分割拆分的方法
- 文件的合并与分割
- 文件的合并与分割
- 文件的分割与合并
- 文件的分割与合并
- 文件的分割与合并
- 文件的分割与合并
- 文件的分割与合并
- java中用文件流分割文件,用于将大文件分割成多个小文件,合并文件待续
- 用java对文件进行分割与合并
- 使用Java对文件进行分割与合并
- KVM架构与原理详解
- 例题6-15 UVa10305 Ordering Tasks(拓扑排序)
- 2-18学习记录
- 手机短信码使用流程
- scala学习
- 将分割的文件进行合并
- Listview中adapter重写的方法以及作用
- Android多媒体框架分析 http://blog.csdn.net/tjy1985/article/category/1109458
- android文件存储的4种方式
- cocoapods安装
- 1004. Counting Leaves (30)
- 多线程超级Ping
- 打开新视界:跳槽不如卧槽!
- 遥感图像滤波处理