我正在寻找 .bat 或 .wsh 脚本的一些示例,它们可以执行以下操作:
- 递归读取具有用户提供的扩展名(.dll、.exe 等)的目录中的文件名 在
- 用户提供的目录中搜索以上文件名
- 中找到 x.txt
生成结果的 txt 或 xls 报告,例如:在“C:\temp”、“C:\blah” TIA
。 编辑:
哎呀,我应该澄清:这里有两个目录和两个搜索。
搜索 1:
- 在用户提供的目录“Dir 1”中搜索所有 *.dll。
搜索 2:
- 在不同的用户提供的目录“Dir 2”中搜索搜索 1 中生成的文件名。此搜索也需要递归。
因此,如果搜索 1 在目录 1 中找到 foo.dll、foo2.dll 和 foo3.dll,则搜索 2 应在目录 2 中查找 foo.dll、foo2.dll 和 foo3.dll,并提供以下报告(简单列表):每个找到的文件。
I am looking for some examples of a .bat OR .wsh script that can do the following:
- Recursively read file names in a directory with a user-provided extension (.dll, .exe, etc)
- Search a user-provided directory for the above file names
- Generate a txt or xls report of the findings, like: x.txt was found in "C:\temp", "C:\blah"
TIA.
EDIT:
Oops, I should clarify: there are two directories and two searches here.
Search 1:
- Search a user provided directory "Dir 1" for all *.dll's.
Search 2:
- Search a different user provided directory "Dir 2" for the file names generated in Search 1. This search also needs to be recursive.
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.
发布评论
评论(3)
为什么不使用目录?
搜索当前目录和所有子目录中的 dll
在所有 C 语言中搜索 dll
保存报告
Why not use dir?
Search current directory and all subdirs for dlls
Search all of C for dlls
Save a report
将以下内容放入 .bat 文件中,例如
FindAll.bat
:%1
是用户提供的文件掩码。%2
是用户提供的首先搜索的目录。%3
是用户提供的第二个搜索目录。从命令行调用以生成报告:
调用批处理文件时添加的
2>&1
为需要捕获文件的所有输出(由此线程提供的aphoria:Windows 批处理文件的未充分利用的功能)Put the following in a .bat file, say
FindAll.bat
:%1
is the user provided file mask.%2
is the user provided directory to search first.%3
is the user provided directory to search second.Call from the command line to generate a report:
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?)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)我会研究 Robocopy 看看这是否有帮助(/L 标志是一个线索)。
I would study Robocopy to see if this could help (the /L flag is a clue).