标题: for与Copy语句的应用案例(新版)
[打印本页]
作者: youlangyu
时间: 2008-9-23 09:48
标题: for与Copy语句的应用案例(新版)
需求:硬盘上有这么一个文件夹,该文件夹下还会有子文件夹,每个文件夹下有很多txt文件,现在要在每个txt文件里的开头部分加入一句话:“this is example",请教如何实现。
上次发表的帖子,有些局限性,比如对文件夹的名称,文件夹的路径有要求,而且,如果有子文件夹,不能直接对子文件夹内的Txt文件操作。
改进后的如下:
md %temp%\a
md %temp%\b
for /r %%k in (*.txt) do (
copy %%k %temp%\a\*.txt
c:
cd %temp%\a
for %%i in (*.txt) do echo "this is example"> %%i
copy %temp%\a\*.txt +%%k %temp%\b\*.txt
copy/y %temp%\b\*.txt %%k
cd..
del/q %temp%\b\*.txt
del/q %temp%\a\*.txt )
cd..
rd %temp%\a
rd %temp%\b
作者: pengzheng
时间: 2008-9-23 23:45
谢谢分享 学习了
作者: xdp4507
时间: 2008-9-25 14:36
好東西啊,不過能不能再做些標示啊對關鍵語句。