共计 3046 个字符,预计需要花费 8 分钟才能阅读完成。
已求得 PY 工具一个,谢谢论坛兄弟。 要求功能如下: 批外理,易语言、PY 或其他键鼠类工具做的都 可以。 谢谢! |
网友回复:
注册 : 整了个半成品,最后一次的文件需要手动合并 先写个 shell 脚本 [[email protected] ~/kafka]$ cat /usr/bin/bbb #!/bin/bash echo 合并 $1 $2 到 $3 cat $1 $2 >> $3 rm $1 rm $2 [[email protected] ~/kafka]$ 复制代码 然后再要合并的目录里执行就可以了 ls | xargs -n 3 bbb 复制代码 会输出 [[email protected] ~/kafka]$ ls | xargs -n 3 bbb 合并 test1 test10 到 test100 合并 test11 test12 到 test13 合并 test14 test15 到 test16 合并 test17 test18 到 test19 合并 test2 test20 到 test21 合并 test22 test23 到 test24 合并 test25 test26 到 test27 合并 test28 test29 到 test3 … 复制代码
liumer: import os # 需要一下设置两个变量 root_path = r”” # 原始文件目录 new_dir = r”” # 生成目录 需要先创建好 n = 0 tmp_file_name = “” files_name = os.listdir(root_path) for file in files_name: if n > 2 or tmp_file_name == “”: tmp_file_name = os.path.join(new_dir, file) n = 0 else: n += 1 file_path = os.path.join(root_path, file) with open(file_path, “r”, encoding=”utf-8″) as fn: with open(tmp_file_name, “a+”, encoding=”utf-8″) as f: f.write(fn.read()) 复制代码
一颗赛艇 : 百度一下大把
beng: 没找到,从昨天开始找到现在没找到,主要就是这每几个合并一起的没有,全部合成一个大文件的找了一堆。
NEET 姬 : 这种自己写一个脚本就行了呀
liumer: 我就是不会罗。
卟想起床 : 我想知道,可以直接用二进制拼接吗?
liumer: 现在领导要求 我手工合并,有 5 千多个文件,愁死我了。
Tankie: 我有,,,pm
liumer: 直接全部合并成一个文件 然后分割份数
司马南 : 分割也不太好分割,一是分割后的文件名不好弄,二是分割容易把一块内容 分成两块了。。
注册 : shell py 都挺好实现的
注册 : 先打开 excel 再用以下的小工具输出文本的绝对路径,然后再三个合成一条。文件合并就是 copy 命令。还不会找我也行。输出文件夹信息.rar (1.47 KB, 下载次数: 1) 4 天前 上传 点击文件名下载附件
ShyGo: PT_Filecomb 不谢
lilyhcn1: import os # 需要一下设置两个变量 root_path = r”” # 原始文件目录 new_dir = r”” # 生成目录 需要先创建好 n = 0 tmp_file_name = “” files_name = os.listdir(root_path) for file in files_name: if n > 2 or tmp_file_name == “”: tmp_file_name = os.path.join(new_dir, file) n = 0 else: n += 1 file_path = os.path.join(root_path, file) with open(file_path, “r”, encoding=”utf-8″) as fn: with open(tmp_file_name, “a+”, encoding=”utf-8″) as f: f.write(fn.read()) 复制代码
之南 : 谢谢,但这个需要手工选择合并的文件,还是不太方便,因为有 5 千多个文件。
beng: 拜谢!您 这方法可行,配合 EXCEL 来写 BAT 文件,应该半小时可完成任务。再次感谢了。
liumer: 那就没啥办法了,单独几个一合并好像没这种软件,只能找人写了~
liumer: 请问这是什么语言?
875: cat * > all.txt
liumer: python
注册 : 整了个半成品,最后一次的文件需要手动合并 先写个 shell 脚本 [[email protected] ~/kafka]$ cat /usr/bin/bbb #!/bin/bash echo 合并 $1 $2 到 $3 cat $1 $2 >> $3 rm $1 rm $2 [[email protected] ~/kafka]$ 复制代码 然后再要合并的目录里执行就可以了 ls | xargs -n 3 bbb 复制代码 会输出 [[email protected] ~/kafka]$ ls | xargs -n 3 bbb 合并 test1 test10 到 test100 合并 test11 test12 到 test13 合并 test14 test15 到 test16 合并 test17 test18 到 test19 合并 test2 test20 到 test21 合并 test22 test23 到 test24 合并 test25 test26 到 test27 合并 test28 test29 到 test3 … 复制代码
注册 : 转换思路啊,小文件合成到一个大文件,然后大文件再拆分成需要大小的小文件。。。搞定。
一颗赛艇 : 大佬,这是什么语言?
acaiplus: 大文件分小文件 时,文件名不好搞。另外容易把一段内容 分成了两块。
liumer: shell
liumer: 大神级,随手就撸出代码了。
一颗赛艇 : from pathlib import Path # 设置文件目录 folder = r’D:testfiles’ path = Path(folder) for file in path.iterdir(): if file.is_file(): # 读取被合并文件 with open(rf'{file}’, mode=’rt’, encoding=’utf-8′) as source_file: # 以源文件名隔开内容 with open(rf’D:testfilesdest_folder/my_file.txt’, mode=’at’, encoding=’utf-8′) as dest_file: dest_file.write(f’n {file.name:*^50} n’) for line in source_file: # 合并文件,文件名为:my_file.txt with open(rf’D:testfilesdest_folder/my_file.txt’, mode=’at’, encoding=’utf-8′) as dest_file: dest_file.write(line)
lilyhcn1: 下个 emeditor pojie 版 然后看这个视频 https://www.bilibili.com/video/av629126147/