打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
批处理经典:遍历目录及替代文件.bat

2006年09月22日 星期五 下午 05:08

遍历目录及替代文件.bat

rem  把目录列表输出到指定文件。。。

dir G:\批目录删除演示\a.txt /s /a /b > dirlist.txt

rem 取出目录列表(把带文件名的目录扩展为只显示目录形式,然后再操作!)
rem 删除当前文件(例如:a.txt,再用其他地方的a.txt文件覆盖当前的a.txt文件。

FOR /F %%I IN (dirlist.txt) DO (cd\ & G:  &  cd %%~pI  & del a.txt  &  copy G:\a.txt  )

rem   可以再次回到原来的目录    cd\  &  G:  &  cd G:\批目录删除演示
rem   可以删除列表文件  dirlist.txt


pause

 

 

参考文本:(下面为参考文本,其他的是一些简单批处理的文章)

:: VisitD.bat - 对指定路径指定目录进行遍历的程序
:: 第一参数为要遍历的目录(支持通配符),第二参数为要遍历的路径(缺省为C盘根)
@echo on

:main
if [a.txt]==[] if not exist dirlist.txt goto end

:init
if exist dirlist.txt if exist xset.asd goto loop 
set dir=a.txt
set base=G:\批目录删除演示
if [%2]==[] set base=c:
dir G:\批目录删除演示\a.txt /s /a /b > dirlist.txt
echo e 100 ‘set  dir=‘ > xset.asd
echo w >> xset.asd
echo q >> xset.asd

:loop
  fc dirlist.txt null.txt /n | find "a.txt" > setfile.bat

rem  fc dirlist.txt null.txt /n | find "a.txt" > setfile.bat

if errorlevel 1 goto restore
debug setdir.bat  nul
call setdir.bat
echo Visiting the dir: %dir%
:: User specified visit code replace this line
find "%dir%" /v  dirlist.tx2
copy dirlist.tx2 dirlist.txt > nul
goto loop

:restore
rem if exist dirlist.txt del dirlist.txt
rem if exist xset.asd del xset.asd
rem if exist dirlist.tx2 del dirlist.tx2
rem if exist setdir.bat del setdir.bat

:end


pause

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
目录文件结构树显示代码
.bat批处理(五):遍历指定目录下资源文件并更新
windows批处理 (cmd/bat) 编程详解
使用DTS导入多个文件数据到SQL Server中
批量打印出歌曲的名称
bat 获取文件目录路径(3种情况,各有配图)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服