我发现每次我把所有的文件连接成一个文件
copy *.txt all.txt
,在文件末尾有一个Ctrl-Z字符。 我不想要这个angular色。 有没有办法写一个批处理脚本来删除这个字符或避免这种情况发生?
我想要做的是
cat *.txt > all.txt
在Linux中。
尝试这个:
copy /b *.txt all.txt
如需帮助,请输入help copy
。
在CP / M日,文件大小不是以字节记录,而是128字节的块。 因此有必要分配一个END-OF-FILE字节(^ Z = 1AH)来表示一个部分填充的文本文件块(并且没有EOF意味着“完全填充最后的128字节块”)
这个惯例被MSDOS及其派生物所尊敬 – 这就是为什么COPY CON: filename
被^ Z终止的原因。
COPY
命令允许对^Z
进行不同的解释 – 因此可以使用/a
和/b
模式,如下面的代码所示:
@ECHO OFF SETLOCAL :: set COPYCMD=Y to auto-allow overwriting of destination SET copycmd=Y :: copy using FRED1.txt (no ^Z-terminal) >NUL COPY /a fred1.txt freda1.txt >NUL COPY fred1.txt fred1a.txt /a >NUL COPY /b fred1.txt fredb1.txt >NUL COPY fred1.txt fred1b.txt /b >NUL COPY /a fred1.txt freda1a.txt /a >NUL COPY /a fred1.txt freda1b.txt /b >NUL COPY /b fred1.txt fredb1a.txt /a >NUL COPY /b fred1.txt fredb1b.txt /b DIR fred*1*|FIND /i "fred" ECHO. :: copy using FRED2.txt (has ^Z-terminal) to fred*2* >NUL COPY /a fred1.txt fred2.txt >NUL COPY /a fred2.txt freda2.txt >NUL COPY fred2.txt fred2a.txt /a >NUL COPY /b fred2.txt fredb2.txt >NUL COPY fred2.txt fred2b.txt /b >NUL COPY /a fred2.txt freda2a.txt /a >NUL COPY /a fred2.txt freda2b.txt /b >NUL COPY /b fred2.txt fredb2a.txt /a >NUL COPY /b fred2.txt fredb2b.txt /b DIR fred*2*|FIND /i "fred" ECHO. :: append-copy using FRED1.txt+FRED2.txt to fred*3* >NUL COPY /a fred1.txt+fred2.txt freda3.txt >NUL COPY fred1.txt+fred2.txt fred3a.txt /a >NUL COPY /b fred1.txt+fred2.txt fredb3.txt >NUL COPY fred1.txt+fred2.txt fred3b.txt /b >NUL COPY /a fred1.txt+fred2.txt freda3a.txt /a >NUL COPY /a fred1.txt+fred2.txt freda3b.txt /b >NUL COPY /b fred1.txt+fred2.txt fredb3a.txt /a >NUL COPY /b fred1.txt+fred2.txt fredb3b.txt /b DIR fred*3*|FIND /i "fred" ECHO. :: append-copy using FRED2.txt+FRED2.txt to fred*4* >NUL COPY /a fred2.txt+fred2.txt freda4.txt >NUL COPY fred2.txt+fred2.txt fred4a.txt /a >NUL COPY /b fred2.txt+fred2.txt fredb4.txt >NUL COPY fred2.txt+fred2.txt fred4b.txt /b >NUL COPY /a fred2.txt+fred2.txt freda4a.txt /a >NUL COPY /a fred2.txt+fred2.txt freda4b.txt /b >NUL COPY /b fred2.txt+fred2.txt fredb4a.txt /a >NUL COPY /b fred2.txt+fred2.txt fredb4b.txt /b DIR fred*4*|FIND /i "fred" ECHO. GOTO :EOF
运行结果:
26/07/2013 08:51 7 fred1.txt 26/07/2013 08:51 7 fred1a.txt 26/07/2013 08:51 7 fred1b.txt 26/07/2013 08:51 8 freda1.txt 26/07/2013 08:51 8 freda1a.txt 26/07/2013 08:51 7 freda1b.txt 26/07/2013 08:51 7 fredb1.txt 26/07/2013 08:51 7 fredb1a.txt 26/07/2013 08:51 7 fredb1b.txt 26/07/2013 08:51 8 fred2.txt 26/07/2013 08:51 8 fred2a.txt 26/07/2013 08:51 8 fred2b.txt 26/07/2013 08:51 8 freda2.txt 26/07/2013 08:51 8 freda2a.txt 26/07/2013 08:51 7 freda2b.txt 26/07/2013 08:51 8 fredb2.txt 26/07/2013 08:51 8 fredb2a.txt 26/07/2013 08:51 8 fredb2b.txt 26/07/2013 09:35 15 fred3a.txt 26/07/2013 09:35 14 fred3b.txt 26/07/2013 09:35 15 freda3.txt 26/07/2013 09:35 15 freda3a.txt 26/07/2013 09:35 14 freda3b.txt 26/07/2013 09:35 15 fredb3.txt 26/07/2013 09:35 16 fredb3a.txt 26/07/2013 09:35 15 fredb3b.txt 26/07/2013 09:35 15 fred4a.txt 26/07/2013 09:35 14 fred4b.txt 26/07/2013 09:35 15 freda4.txt 26/07/2013 09:35 15 freda4a.txt 26/07/2013 09:35 14 freda4b.txt 26/07/2013 09:35 16 fredb4.txt 26/07/2013 09:35 17 fredb4a.txt 26/07/2013 09:35 16 fredb4b.txt
请注意,juxataposing /a
和/b
如何产生不同的结果,全部使用^Z
-inclusion或甚至附加的各种组合。
还要注意,如果源是一个二进制文件并且省略了/b
开关,简单的COPY
可能会失败。 我从来没有调查过,但我偶然发现它复制.MPG
s。 我怀疑,如果^Z
在任何字节> = 80H之前出现在文件中,那么该文件被认为是ASCII,因此在那里随便终止 – 但正如我所说,我没有调查它。