我有一个包含名称列表的TXT文件:
Test
Word
etc.
如果其中一个名称与文件匹配,我需要搜索(递归,也在子文件夹中)。这是我的尝试:
@echo off
Set MyPath=C:\Folder
for /f %%i in (list.txt) do (
echo File with word %%i: >> result.txt
echo. >> result.txt
findstr /M /C:%%i /S "%MyPath%\*.*" >> result.txt
echo. >> result.txt
)
我想要的result.txt是:
File with word test:
C:\Folder\test.exe
C:\Folder\my test.txt
C:\Folder\another test.doc
C:\Folder\tatest.bat
File with word Word:
C:\Folder\This is my word.exe
C:\Folder\CoolWord.txt
C:\Folder\hello word.bat
那么如何改进该批处理并使其也为初始目录的子文件夹递归?
由于
答案 0 :(得分:1)
测试一下:它会将result.txt写成每个单词的结果。
@echo off
(
for /f "usebackq delims=" %%a in ("list.txt") do (
echo "File with word %%a:"
echo.
set "flag="
for /r "c:\folder" %%b in ("*%%a*") do (echo %%b&set flag=1)
if not defined flag echo No Matches
echo.
)
)>"result.txt"
答案 1 :(得分:0)
dir /s /b C:\Folder\*.* >allfiles.txt
for /f %%i in (list.txt) do (
echo File with word %%i: >> result.txt
echo. >> result.txt
findstr /M /C:%%i /S "allfiles.txt" >> result.txt
echo. >> result.txt
)
答案 2 :(得分:0)
@echo off
Set MyPath=C:\Folder
(for /f "delims=" %%i in (list.txt) do (
echo File with word %%i:
echo/
dir /B /S "%MyPath%\*%%i*"
echo/
)) > result.txt