[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 【已解决】求助一个批处理可以搜索此文件夹下所有xml内容的文本

本帖最后由 zhengwei007 于 2024-2-29 23:19 编辑

事情是这样的,比如我有100个XML文件,里面全是纯文本内容。
我想通过一个批处理文件,运行后能找到我想查找的关键词在哪个文件里面存在。
比如有10个文件,我想查找一组数字12345。那么我在批处理中编辑时把12345打进去。
运行后,所有包含12345字符的文件名就提取出来了,然后把所有符合条件的文件名存在sour.txt中即可。
我上传了3个小文件,我在批处理中输入查找关键词:http://www.w3.org,然后保存退出再运行。
得到的结果应该是:
001.xml
002.xml
003.xml

如果没有符合的,直接返回空的就行。谢谢大佬们。
由于文件无法上传,我直接将3个文件中随意拿点出来。
001.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/multisell.xsd">
  3. <item>
  4. <!-- Adena -->
  5. <ingredient count="2100" id="57" />
  6. <!-- Shirt -->
  7. <ingredient count="1" id="21" />
  8. <!-- Leather Shirt -->
  9. <production count="1" id="22" />
  10. </item>
  11. <item>
  12. <!-- Adena -->
  13. <ingredient count="5400" id="57" />
  14. <!-- Leather Shirt -->
  15. <ingredient count="1" id="22" />
  16. <!-- Wooden Breastplate -->
  17. <production count="1" id="23" />
  18. </item>
  19. <item>
  20. <!-- Adena -->
  21. <ingredient count="12200" id="57" />
  22. <!-- Wooden Breastplate -->
  23. <ingredient count="1" id="23" />
  24. <!-- Bone Breastplate -->
  25. <production count="1" id="24" />
  26. </item>
  27. <item>
  28. <!-- Adena -->
  29. <ingredient count="16500" id="57" />
  30. <!-- Bone Breastplate -->
  31. <ingredient count="1" id="24" />
  32. <!-- Piece Bone Breastplate -->
  33. <production count="1" id="25" />
  34. </item>
  35. <item>
  36. <!-- Adena -->
  37. <ingredient count="16500" id="57" />
  38. <!-- Bone Breastplate -->
  39. <ingredient count="1" id="24" />
  40. <!-- Hard Leather Shirt -->
  41. <production count="1" id="27" />
  42. </item>
  43. <item>
  44. <!-- Adena -->
  45. <ingredient count="16500" id="57" />
  46. <!-- Piece Bone Breastplate -->
  47. <ingredient count="1" id="25" />
  48. <!-- Bronze Breastplate -->
  49. <production count="1" id="26" />
  50. </item>
  51. </list>
复制代码
002.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/multisell.xsd">
  3. <npcs>
  4. <npc>30006</npc> <!-- Roxxy (Gatekeeper) -->
  5. <npc>30059</npc> <!-- Trisha (Gatekeeper) -->
  6. <npc>30080</npc> <!-- Clarissa (Gatekeeper) -->
  7. <npc>30134</npc> <!-- Jasmine (Gatekeeper) -->
  8. <npc>30146</npc> <!-- Mirabel (Gatekeeper) -->
  9. <npc>30177</npc> <!-- Valentina (Gatekeeper) -->
  10. <npc>30233</npc> <!-- Esmeralda (Gatekeeper) -->
  11. <npc>30256</npc> <!-- Bella (Gatekeeper) -->
  12. <npc>30320</npc> <!-- Richlin (Gatekeeper) -->
  13. <npc>30540</npc> <!-- Wirphy (Gatekeeper) -->
  14. <npc>30576</npc> <!-- Tamil (Gatekeeper) -->
  15. <npc>30727</npc> <!-- Verona (Gatekeeper) -->
  16. <npc>30836</npc> <!-- Minerva (Gatekeeper) -->
  17. <npc>30848</npc> <!-- Elisa (Gatekeeper) -->
  18. <npc>30878</npc> <!-- Angelina (Gatekeeper) -->
  19. <npc>30899</npc> <!-- Flauen (Gatekeeper) -->
  20. <npc>31275</npc> <!-- Tatiana (Gatekeeper) -->
  21. <npc>31320</npc> <!-- Ilyana (Gatekeeper) -->
  22. <npc>31964</npc> <!-- Bilia (Gatekeeper) -->
  23. <npc>32163</npc> <!-- Ragara (Gatekeeper) -->
  24. </npcs>
  25. <item>
  26. <!-- Dimensional Diamond -->
  27. <ingredient count="5" id="7562" />
  28. <!-- Scroll of Escape: Talking Island Village -->
  29. <production count="1" id="7117" />
  30. </item>
  31. <item>
  32. <!-- Dimensional Diamond -->
  33. <ingredient count="5" id="7562" />
  34. <!-- Scroll of Escape: Elven Village -->
  35. <production count="1" id="7118" />
  36. </item>
  37. <item>
  38. <!-- Dimensional Diamond -->
  39. <ingredient count="5" id="7562" />
  40. <!-- Scroll of Escape: Dark Elven Village -->
  41. <production count="1" id="7119" />
  42. </item>
  43. <item>
  44. <!-- Dimensional Diamond -->
  45. <ingredient count="5" id="7562" />
  46. <!-- Scroll of Escape: Orc Village -->
  47. <production count="1" id="7120" />
  48. </item>
  49. <item>
  50. <!-- Dimensional Diamond -->
  51. <ingredient count="5" id="7562" />
  52. <!-- Scroll of Escape: Kamael Village -->
  53. <production count="1" id="9716" />
  54. </item>
  55. <item>
  56. <!-- Dimensional Diamond -->
  57. <ingredient count="5" id="7562" />
  58. <!-- Scroll of Escape: Dwarven Village -->
  59. <production count="1" id="7121" />
  60. </item>
  61. <item>
  62. <!-- Dimensional Diamond -->
  63. <ingredient count="8" id="7562" />
  64. <!-- Scroll of Escape: Gludin Village -->
  65. <production count="1" id="7122" />
  66. </item>
  67. <item>
  68. <!-- Dimensional Diamond -->
  69. <ingredient count="8" id="7562" />
  70. <!-- Scroll of Escape: Town of Gludio -->
  71. <production count="1" id="7123" />
  72. </item>
  73. <item>
  74. <!-- Dimensional Diamond -->
  75. <ingredient count="8" id="7562" />
  76. <!-- Scroll of Escape: Town of Dion -->
  77. <production count="1" id="7124" />
  78. </item>
  79. <item>
  80. <!-- Dimensional Diamond -->
  81. <ingredient count="8" id="7562" />
  82. <!-- Scroll of Escape: Floran Village -->
  83. <production count="1" id="7125" />
  84. </item>
  85. <item>
  86. <!-- Dimensional Diamond -->
  87. <ingredient count="8" id="7562" />
  88. <!-- Scroll of Escape: Town of Giran -->
  89. <production count="1" id="7126" />
  90. </item>
  91. <item>
  92. <!-- Dimensional Diamond -->
  93. <ingredient count="8" id="7562" />
  94. <!-- Scroll of Escape: Hardin's Academy -->
  95. <production count="1" id="7127" />
  96. </item>
  97. <item>
  98. <!-- Dimensional Diamond -->
  99. <ingredient count="8" id="7562" />
  100. <!-- Scroll of Escape: Heine -->
  101. <production count="1" id="7128" />
  102. </item>
  103. <item>
  104. <!-- Dimensional Diamond -->
  105. <ingredient count="8" id="7562" />
  106. <!-- Scroll of Escape: Town of Oren -->
  107. <production count="1" id="7129" />
  108. </item>
  109. <item>
  110. <!-- Dimensional Diamond -->
  111. <ingredient count="8" id="7562" />
  112. <!-- Scroll of Escape: Ivory Tower -->
  113. <production count="1" id="7130" />
  114. </item>
  115. <item>
  116. <!-- Dimensional Diamond -->
  117. <ingredient count="8" id="7562" />
  118. <!-- Scroll of Escape: Hunters Village -->
  119. <production count="1" id="7131" />
  120. </item>
  121. <item>
  122. <!-- Dimensional Diamond -->
  123. <ingredient count="8" id="7562" />
  124. <!-- Scroll of Escape: Town of Aden -->
  125. <production count="1" id="7132" />
  126. </item>
  127. <item>
  128. <!-- Dimensional Diamond -->
  129. <ingredient count="8" id="7562" />
  130. <!-- Scroll of Escape: Town of Goddard -->
  131. <production count="1" id="7133" />
  132. </item>
  133. <item>
  134. <!-- Dimensional Diamond -->
  135. <ingredient count="8" id="7562" />
  136. <!-- Scroll of Escape: Rune Township -->
  137. <production count="1" id="7134" />
  138. </item>
  139. <item>
  140. <!-- Dimensional Diamond -->
  141. <ingredient count="8" id="7562" />
  142. <!-- Scroll of Escape: Town of Schuttgart -->
  143. <production count="1" id="7135" />
  144. </item>
  145. </list>
复制代码
003.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/multisell.xsd">
  3. <npcs>
  4. <npc>30001</npc> <!-- Lector (Weapon Merchant) -->
  5. <npc>30002</npc> <!-- Jackson (Armor Merchant) -->
  6. <npc>30003</npc> <!-- Silvia (Accessory Merchant) -->
  7. <npc>30135</npc> <!-- Iria (Weapon Merchant) -->
  8. <npc>30136</npc> <!-- Payne (Armor Merchant) -->
  9. <npc>30138</npc> <!-- Minaless (Accessory Merchant) -->
  10. <npc>30147</npc> <!-- Unoren (Weapon Merchant) -->
  11. <npc>30148</npc> <!-- Ariel (Armor Merchant) -->
  12. <npc>30149</npc> <!-- Creamees (Accessory Merchant) -->
  13. <npc>30207</npc> <!-- Arodin (Weapon Merchant) -->
  14. <npc>30208</npc> <!-- Damion (Armor Merchant) -->
  15. <npc>30253</npc> <!-- Simplon (Armor Merchant) -->
  16. <npc>30294</npc> <!-- Varan (Accessory Merchant) -->
  17. <npc>30314</npc> <!-- Nestle (Accessory Merchant) -->
  18. <npc>30321</npc> <!-- Sydnia (Weapon Merchant) -->
  19. <npc>30516</npc> <!-- Reep (Weapon Merchant) -->
  20. <npc>30517</npc> <!-- Shari (Armor Merchant) -->
  21. <npc>30518</npc> <!-- Garita (Accessory Merchant) -->
  22. <npc>30519</npc> <!-- Mion (Grocer) -->
  23. <npc>30558</npc> <!-- Jakal (Weapon Merchant) -->
  24. <npc>30559</npc> <!-- Kunai (Armor Merchant) -->
  25. <npc>30560</npc> <!-- Uska (Accessory Merchant) -->
  26. <npc>32164</npc> <!-- Erinu (Weapon Merchant) -->
  27. <npc>32165</npc> <!-- Zakone (Armor Merchant) -->
  28. <npc>32166</npc> <!-- Trevor (Accessory Merchant) -->
  29. </npcs>
  30. <item>
  31. <!-- Club -->
  32. <ingredient count="1" id="4" />
  33. <!-- Adena -->
  34. <ingredient count="8032" id="57" />
  35. <!-- Heavy Chisel -->
  36. <production count="1" id="152" />
  37. </item>
  38. <item>
  39. <!-- Heavy Chisel -->
  40. <ingredient count="1" id="152" />
  41. <!-- Adena -->
  42. <ingredient count="4873" id="57" />
  43. <!-- Mace -->
  44. <production count="1" id="5" />
  45. </item>
  46. <item>
  47. <!-- Mace -->
  48. <ingredient count="1" id="5" />
  49. <!-- Adena -->
  50. <ingredient count="6600" id="57" />
  51. <!-- Sigil -->
  52. <production count="1" id="153" />
  53. </item>
  54. <item>
  55. <!-- Sigil -->
  56. <ingredient count="1" id="153" />
  57. <!-- Adena -->
  58. <ingredient count="39160" id="57" />
  59. <!-- Dwarven Mace -->
  60. <production count="1" id="154" />
  61. </item>
复制代码
大家复制出来随便保存一下。
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

  1. @echo off
  2. (for /f "delims=" %%i in ('dir /b *.xml') do (
  3.     find /i "http://www.w3.org" "%%i" >nul && echo %%i
  4. )) >sour.txt
  5. pause
复制代码
1

评分人数

    • GNGW: 乐于助人技术 + 1

QQ 20147578

TOP

  1. @echo off
  2. findstr /im /c:"http://www.w3.org" *.xml
  3. pause
复制代码

TOP

本帖最后由 zhengwei007 于 2024-2-29 18:14 编辑
czjt1234 发表于 2024-2-29 14:55


不好意思没说清,当前目录下的所有目录需要遍历一遍,保存结果时也要把路径带上。

TOP

本帖最后由 zhengwei007 于 2024-2-29 18:14 编辑
qixiaobin0715 发表于 2024-2-29 15:04


不好意思没说清,当前目录下的所有目录需要遍历一遍,保存结果时也要把路径带上。

TOP

  1. @echo off
  2. (for /f "delims=" %%i in ('dir /s /b *.xml') do (
  3.     find /i "http://www.w3.org" "%%i" >nul && echo %%i
  4. )) >sour.txt
  5. pause
复制代码
1

评分人数


QQ 20147578

TOP

要不就用ripgrep,4000个文本,5g,1秒

TOP

czjt1234 发表于 2024-2-29 18:26


谢谢,就是这样的,完全符合。太棒了!

TOP

本帖最后由 qixiaobin0715 于 2024-3-1 10:50 编辑

3楼代码加个“/s”参数,可以得到相对路径:
  1. findstr /ims /c:"http://www.w3.org" *.xml
复制代码
获得全路径:
  1. @echo off
  2. for /f "delims=" %%i in ('findstr /ims /c:"http://www.w3.org" *.xml') do echo,%~dp0%%i
  3. pause
复制代码

TOP

回复 9# qixiaobin0715


    不加 for 应该可以吧?
findstr /i /m /s /c:"abcd" "%~dp0*.txt"

TOP

本帖最后由 WHY 于 2024-3-1 20:42 编辑
  1. PowerShell "(dir *.txt -Recurse | Select-String 'abcd' -SimpleMatch -List).Path"
复制代码

TOP

回复 10# WHY

TOP

返回列表