求一个BAT的写法

来源:百度知道 编辑:UC知道 时间:2024/06/09 17:20:34
问题是这样的,我想把一个文件加里面的所有的*.TXT格式的文件的头部和尾部都加上一段话,请高手给个方法,很多文件不可能手动修改

在你的文件夹下面新建一个head.txt文件,将你要添加的文件头部内容放在里面
同样的新建一个tail.txt文件,将你要添加的文件尾部内容放在里面。

然后打开记事本程序,将以下内容复制进去。再以bat.bat文件名保存,然后双击这个bat.bat文件就可以了。如果顺利的话,应当会产生一个OK文件夹,里面放处理好的文件。

@echo off
if exist head.txt ren head.txt head.1
if exist tail.txt ren tail.txt tail.1

if exist head.1 goto existhead
echo 不存在head.txt文件
goto end
:existhead
if exist tail.1 goto existtail
echo 不存在tail.txt文件
goto end
:existtail
if exist ok goto op
md ok

:op
for %%c in (*.txt) do copy head.1+%%c+tail.1 ok\%%c

:end
if exist head.1 ren head.1 head.txt
if exist tail.1 ren tail.1 tail.txt
pause