chr*_*ome 6 scripting wsh batch-file
我正在寻找一些可以执行以下操作的.bat OR .wsh脚本示例:
TIA.
编辑:
哎呀,我应该澄清一下:这里有两个目录和两个搜索.
搜索1:
搜索2:
因此,如果搜索1在目录1中找到foo.dll,foo2.dll和foo3.dll,则搜索2应在目录2中查找foo.dll,foo2.dll和foo3.dll,并提供报告(简单列表)每个找到的文件.
Tom*_*ter 18
为什么不使用dir?
搜索当前目录和dll的所有子目录
Run Code Online (Sandbox Code Playgroud)dir /S *.dll
搜索所有C的dll
Run Code Online (Sandbox Code Playgroud)dir /S C:\*.dll
保存报告
Run Code Online (Sandbox Code Playgroud)dir /S C:\*.dll > report.txt
将以下内容放在.bat文件中,例如FindAll.bat:
@echo OFF
for /f %%F in ('dir %2\%1 /s /b') do (
<nul (set /p msg=%%~nxF )
for /f %%G in ('dir %3\%%~nxF /s /b') do (
if exist %%G (
@echo found at %%G
)
)
)
Run Code Online (Sandbox Code Playgroud)
%1 是用户提供的文件掩码.
%2 是用户提供的目录,首先进行搜索.
%3 是用户提供的第二个搜索目录.
从命令行调用以生成报告:
FindAll *.dll d:\dir1 d:\dir2 > dll_report.txt 2>&1
Run Code Online (Sandbox Code Playgroud)
这个<nul (set /p)技巧会在没有新行的情况下将文本输出到控制台(来自这个线程的Pax提供:如何编写微调器以便在批处理文件中等待进程?)
在2>&1添加时调用批处理文件是需要捕获所有的输出到文件(礼貌aphoria从这个线程:的Windows批处理文件未充分利用的功能)