[英]Batch script to read from file name from source file and write path of all occurrences into output file
I need a batch script that reads a value from a file and searches for it in a directory tree.我需要一个从文件中读取值并在目录树中搜索它的批处理脚本。 It should print paths and file name of all the occurrences into an output file.它应该将所有出现的路径和文件名打印到输出文件中。 The in put file will have multiple values.输入文件将有多个值。
Directory structure
Dir1/DirA/file.txt
Dir1/DirA/file1.txt
Dir1/DirB/file.txt
Dir1/DirA/file2.txt
Dir1/DirC/file5.txt
Dir1/DirX/file5.txt
Source file
file.txt
file1.txt
file2.txt
file5.txt
file9.txt
Desired Output file
Dir1/DirA/file.txt
Dir1/DirB/file.txt
file.txt Count 2
Dir1/DirA/file1.txt
file1.txt Count 1
Dir1/DirA/file2.txt
file1.txt Count 1
Dir1/DirC/file5.txt
Dir1/DirX/file5.txt
file5.txt Count 2
file9.txt Count 0
There are two critical components in this solution: one get the path and the file name together, the second one to test if the file exist.此解决方案中有两个关键组件:一个是获取路径和文件名,第二个是测试文件是否存在。
Use the modify to get path info http://technogadge.com/how-to-clear-vivaldi-browser-history-cache-cookies/使用修改获取路径信息http://technogadge.com/how-to-clear-vivaldi-browser-history-cache-cookies/
Use the exist keyword in if statement to detect if the file exist使用 if 语句中的exist关键字来检测文件是否存在
if exist filepath (如果存在文件路径(
echo "got it"回声“明白了”
) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.