一个.bat或.wsh脚本,它可以搜索文件 [英] A .bat or .wsh script that can search for files

查看:187
本文介绍了一个.bat或.wsh脚本,它可以搜索文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个.bat或.wsh脚本,可以做以下的一些例子:

I am looking for some examples of a .bat OR .wsh script that can do the following:


  • 递归与用户提供的扩展名的目录中读取文件名文件(.dll,.exe文件等)

  • 搜索用户提供的目录上面的文件名

  • 生成的结果,就像一个txt或XLS报告:x.txt在找到C:\\ TEMP,C:\\嗒嗒

TIA。

编辑:

哎呀,我要澄清:有两个目录和两个在这里搜索

Oops, I should clarify: there are two directories and two searches here.

搜索1:


  • 搜索用户提供的目录目录1所有的* .dll的。

搜索2:


  • 搜索不同的用户提供的目录目录2中搜索1.此搜索也需要递归生成的文件名。

所以,如果搜索发现1在方向1 foo.dll,foo2.dll和foo3.dll,搜索2应该看看风向2 foo.dll,foo2.dll和foo3.dll,并提供报告(简每个找到的文件的列表)。

So, if Search 1 finds foo.dll, foo2.dll and foo3.dll in Dir 1, Search 2 should look in Dir 2 for foo.dll, foo2.dll and foo3.dll, and provide a report (simple listing) of each found file.

推荐答案

将下面的.bat文件,说 FindAll.bat

Put the following in a .bat file, say 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
        ) 
    )
)

%1 为用户提供的文件掩码。

%1 is the user provided file mask.

%2 为用户提供的目录先搜索

%2 is the user provided directory to search first.

3%为用户提供的目录来第二次搜索。

%3 is the user provided directory to search second.

从命令行调用生成报表:

Call from the command line to generate a report:

FindAll *.dll d:\dir1 d:\dir2 > dll_report.txt 2>&1

&LT; NUL(套/ P)把戏,输出文本到控制台而不换行(礼貌的此线程大同:<一href=\"http://stackoverflow.com/questions/368041/how-to-$c$c-a-spinner-for-waiting-processes-in-a-batch-file#371276\">How至code进行微调在一个批处理文件等待的进程?)

The <nul (set /p) trick will output text to the console without a new line (courtesy Pax from this thread: How to code a spinner for waiting processes in a Batch file?)

2 - ;&放大器; 1 添加调用批处理文件时需要捕获所有的输出到文件(礼貌的 aphoria 此主题:<一href=\"http://stackoverflow.com/questions/245395/underused-features-of-windows-batch-files#246691\">Underused的Windows批处理文件功能)

The 2>&1 added when calling the batch file is needed to capture all the output to the file (courtesy aphoria from this thread: Underused features of Windows batch files)

这篇关于一个.bat或.wsh脚本,它可以搜索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆