赵本山小品拜年,3.8大案,潮剧
支持两种用法:
(1)合并某一文件夹下的所有文件(忽略文件夹等非文件条目)
(2)显示的合并多文件。
import sys
import os
'''
usage(1): merge_files pathname
pathname is directory and merge files in pathname directory
usage(2): merge_files file1 file2 [file3[...]]
'''
file_slim = (256*(1024*1024)) #256m match 2**n
def merge_files(fileslist,mfname):
global file_slim
p_fp = open(mfname,"wba")
for file in fileslist:
with open(file,"rb") as c_fp:
fsize = os.stat(file).st_size
count = fsize&file_slim
while count>0:
p_fp.write(c_fp.read(file_slim))
fsize -= file_slim
count -= 1
p_fp.write(c_fp.read())
p_fp.close
def main():
argc = len(sys.argv) - 1
fileslist = []
if argc == 2:
dir_name = os.path.realpath(sys.argv[1])
assert(os.path.isdir(dir_name))
file_dir = os.listdir(dir_name)
fileslist = [os.path.join(dir_name,file) for file in file_dir if os.path.isfile(os.path.join(dir_name,file))]
print(fileslist)
elif argc >=3:
fileslist = [os.path.realpath(sys.argv[index]) for index in range(1,argc) if os.path.isfile(os.path.realpath(sys.argv[index]))]
merge_files(fileslist,sys.argv[argc])
if __name__ == '__main__':
main()
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
python如何查看网页代码
用python查看网页代码的方法:1、使用“import”导入requests包import requests2、使用requests包的get()函数通过网页...
[阅读全文]
-
-
python如何保存文本文件
python保存文本文件的方法:使用python内置的open()类可以打开文本文件,向文件里面写入数据可以用write()函数,写完之后,使用close()函...
[阅读全文]
-
python如何编写win程序
python可以编写win程序。win程序的格式是exe,下面我们就来看一下使用python编写exe程序的方法。编写好python程序后py2exe模块即可将...
[阅读全文]
-
-
-
-
-
-
网友评论