简体   繁体   English

批处理脚本从源文件中读取文件名并将所有出现的路径写入输出文件

[英]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.此解决方案中有两个关键组件:一个是获取路径和文件名,第二个是测试文件是否存在。

  1. 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/

  2. 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.

相关问题 从批处理文件中的.txt文件读取路径 - read path from a .txt file in a batch file 从批处理脚本中的.lnk快捷方式获取源.exe文件名? - Getting the source .exe file name from .lnk shortcut in batch script? 批处理文件以计算文件夹中的所有文件和子文件夹文件,并使用批处理文件以文件夹名称写入输出文件 - batch file to count all files in a folder and subfolder files and write output file in folder name using batch file 从批处理文件的路径中提取文件夹名称 - Extract folder name from path in batch file 在批处理脚本中读取文件并从中获取值 - Read a file and obtain a value from it in batch script 如何将目录中的所有* .txt文件写入一个文件中,并在输出文件的每一行中包含源文件名? - How to write all *.txt files in a directory into one file with source file name in each line in output file? 如何在输出重定向中使用vbscript变量从批处理脚本写入配置文件 - How can I write a config file from batch script using vbscript variables in output redirect Windows批处理脚本:将所有输出重定向到文件 - Windows Batch Script: Redirect ALL output to a file 如何从 Windows 批处理脚本中的文件路径获取父目录名称? - How to get parent directory name from path of a file in a Windows batch script? 在批处理脚本中将最近修改的文件从源复制到目标 - copy the recently modified file from source to destination in Batch script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM