Board logo

标题: [文本处理] [已解决]批处理搜索当前目录及子目录中包含指定字符的文件名并写入另一文件中 [打印本页]

作者: temp    时间: 2011-5-16 23:06     标题: [已解决]批处理搜索当前目录及子目录中包含指定字符的文件名并写入另一文件中

本帖最后由 temp 于 2011-5-19 12:32 编辑

搜索命令:
  1. @echo off&setlocal enabledelayedexpansion
  2. title=  查找包含.dll .ax字符行
  3. for /f "delims=" %%i in ('dir/b/s/a-d "%~dp0Bin\*.dll"') do echo %%i>>a.txt
  4. for /f "delims=" %%i in ('type "a.txt"') do (if not defined %%i set %%i=A & echo Regsvr32/s "%%i">>"1.cmd")
复制代码
结果:
  1. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AddrSearch.dll"
  2. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AFCtrl.dll"
  3. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AFUtil.dll"
  4. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AppCom.dll"
  5. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AppFramework.dll"
  6. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AppMisc.dll"
  7. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AppUtil.dll"
  8. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\AuCommon.dll"
  9. Regsvr32/s "D:\Documents and Settings\Administrator\桌面\Tencent\QQ\Bin\audioengine.dll"
  10. ... ...
复制代码
我希望得到的结果:
  1. Regsvr32/s "Bin\XVEngine.dll"
  2. Regsvr32/s "Bin\AddrSearch.dll"
  3. Regsvr32/s "Bin\AFCtrl.dll"
  4. Regsvr32/s "Bin\AFUtil.dll"
  5. Regsvr32/s "Bin\AppCom.dll"
  6. Regsvr32/s "Bin\AppFramework.dll"
  7. Regsvr32/s "Bin\AppMisc.dll"
  8. Regsvr32/s "Bin\AppUtil.dll"
  9. ... ...
复制代码
谢谢!
作者: CrLf    时间: 2011-5-16 23:14

用%%~nxi代替%%i
作者: temp    时间: 2011-5-18 21:48

用%%~nxi代替%%i
zm900612 发表于 2011-5-16 23:14

谢谢!

我试了,没成功,请帮忙贴上完整的代码
作者: CrLf    时间: 2011-5-18 22:50

  1. @echo off&setlocal enabledelayedexpansion
  2. title=  查找包含.dll .ax字符行
  3. for /f "delims=" %%i in ('dir/b/s/a-d "%~dp0Bin\*.dll"') do echo %%i>>a.txt
  4. for /f "delims=" %%i in ('type "a.txt"') do (
  5.    if not defined %%i set %%i=A & echo Regsvr32/s "Bin\%%~nxi">>"1.cmd"
  6. )
复制代码

作者: temp    时间: 2011-5-18 23:50

本帖最后由 temp 于 2011-5-19 12:31 编辑
@echo off&setlocal enabledelayedexpansion
title=  查找包含.dll .ax字符行
for /f "delims=" %%i in ('dir/b/s/a-d "%~dp0Bin\*.dll"') do echo %%i>>a.txt
for /f "delims=" %%i in ('type "a.txt"') do (
  ...
zm900612 发表于 2011-5-18 22:50

谢谢!
已达到预期效果(问题出在重复执行了一遍一楼的代码)




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2