繁体   English   中英

批处理脚本以从文本文件中读取特定单词并写入另一个文件

[英]Batch script to read specific word from a text file and write to another file

我需要批处理脚本的一些帮助,该脚本必须实现以下目的:

  1. 放在根结构中,带有#个文件夹
  2. 打开每个子文件夹,然后从文本文件中读出特定的一行(文件名各不相同)。
  3. 根据先前搜索到的行,创建另一个文本文件以显示“确定”或“不正确”。

在此先感谢任何可以帮助我的人。

我猜可能是这样的:

  • 它在每个文件夹中搜索* .txt文件。
  • 读取每个文件中的字符串“ This is my line”
  • 如果找到,它将在D:\\ FileStatus.txt中写入“ filename.txt”是可以的
  • 如果找不到,它将在D:\\ FileStatus.txt中写入“ filename.txt”是不正确的

@回声关闭

Set DirToSearch="D:\MyFolders\"
Set LineToRead="This is my line"

pushd %DirToSearch%
for /r %%f in (*.txt) do (
    For /F %%l in ('Findstr /L /I %LineToRead% "%%f"') do (
     if %%l equ " " (
        echo File:"%%f" is Not OK >> D:\FileStatus.txt
     ) else (
        echo Line: %%l
        echo File:"%%f" is OK >> D:\FileStatus.txt
     )
)
)

Goto :End

:End
popd

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM