Findstr返回整行,是行包含X.

时间:2018-02-28 23:08:07

标签: batch-file findstr

我现在在网上搜索了2个小时,无法找到我要找的东西。

基本上,我想脚本搜索整个驱动​​器的特定文件。

我发现这样做的最佳方法是将所有文件夹和文件输出到dir /s的输出文件。然后,我使用findstr将我的搜索参数文件与dir输出进行比较。搜索工作......但它只是发现它找到的具体事物。

我得到的结果

notepad.exe
download.bat

我想要的结果是

c:\windows\notepad.exe
c:\download.bat

。 。 。或者如果你的代码只是搜索驱动器上的东西,那就完美了。我实际上只想要路径,而不是dir /s中找到的整行。

无论哪种方式,都是我正在玩的一些代码。

@echo off

set dir_out=c:\dir_output.txt
set search=C:\in.txt
set out=c:\Match_Output.txt

echo delelting old %search% file
if exist  %search% del %search% /f

echo delelting old %out% file
if exist  %out% del %out% /f

echo delelting old %dir_out% file
if exist  %dir_out% del %dir_out% /f

echo creating new %search% file
echo notepad.exe >> %search%
echo download.bat >> %search%

echo changing to root directory
cd\

echo outputing entire c:\ into log file
dir /s >> %dir_out%

echo matching log file
findstr /ixg:%search% %dir_out% >> %out%

0 个答案:

没有答案
相关问题