我需要在Windows上用*.bat脚本连接两个二进制文件。

我怎样才能做到呢?


当前回答

Windows type命令的工作原理类似于UNIX cat。

示例1:

type file1 file2 > file3

等价于:

cat file1 file2 > file3

示例2:

type  *.vcf > all_in_one.vcf  

这个命令将所有的vcard合并为一个。

其他回答

Windows type命令的工作原理类似于UNIX cat。

示例1:

type file1 file2 > file3

等价于:

cat file1 file2 > file3

示例2:

type  *.vcf > all_in_one.vcf  

这个命令将所有的vcard合并为一个。

如果你必须使用批处理脚本并安装python,这里有一个多语言的批处理和python回答:

1>2# : ^
'''
@echo off
python "%~nx0" " %~nx1" "%~nx2" "%~nx3"
exit /b
rem ^
'''
import sys
import os

sys.argv = [argv.strip() for argv in sys.argv]
if len(sys.argv) != 4:
    sys.exit(1)

_, file_one, file_two, out_file = sys.argv

for file_name in [file_one, file_two]:
    if not os.path.isfile(file_name):
        print "Can't find: {0}".format(file_name)
        sys.exit(1)

if os.path.isfile(out_file):
    print "Output file exists and will be overwritten"

with open(out_file, "wb") as out:
    with open(file_one, "rb") as f1:
        out.write(f1.read())

    with open(file_two, "rb") as f2:
        out.write(f2.read())

如果保存为join.bat,则用法如下:

join.bat file_one.bin file_two.bin out_file.bin

谢谢你的灵感。

我尝试重新加入tar存档,它已经在Linux服务器上被分裂。

我发现如果我在Windows的cmd.exe中使用类型,它会导致文件以错误的顺序连接。类型有时会输入XXXX。先是广告,然后是XXXX。ac, XXXX。Aa等等…)

所以,我在GitHub https://github.com/sharkdp/bat找到了一个名为bat的工具,它有一个Windows构建,并有更好的代码高亮显示,重要的是,它可以在Windows上重新加入tar存档!

无耻的PowerShell插头(因为我认为学习曲线是一种痛苦,所以在任何机会教一些东西会有所帮助)

Get-Content file1,file2

注意,type是Get-Content的别名,所以如果你更喜欢它,你可以这样写:

type file1,file2

只需对多个源文件和一个目标文件使用dos复制命令。

copy file1+file2 appendedfile

二进制文件可能需要/B选项