windows 批处理文件以检查文件中是否存在特定单词“test”,如果存在则将整个文件夹复制到另一个位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6790448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:33:01  来源:igfitidea点击:

batch file to check if the specific word "test" exist in the files, IF exist copy the whole folder to another location

windowsbatch-filecmdxcopy

提问by massaki

How can I check if the word "test" exist in any files inside a folder(that contain tons of folders and files) .. and if exist, copy the whole folder to another location.

如何检查文件夹内的任何文件(包含大量文件夹和文件)中是否存在“test”一词……如果存在,请将整个文件夹复制到另一个位置。

Please help thank you

请帮忙谢谢

回答by Aacini

findstr /c:"test" *.txt > NUL
if not errorlevel 1 xcopy *.* anotherlocation

If you want to check all files beneath current folder at any level, add /S switch in findstr command. Do the same in xcopy command to copy the whole folder structure.

如果要检查当前文件夹下任何级别的所有文件,请在 findstr 命令中添加 /S 开关。在 xcopy 命令中执行相同操作以复制整个文件夹结构。

回答by user1942990

@echo off 
SETLOCAL ENABLEDELAYEDEXPANSION 
findstr /c:"Finished schedule" E:\Init.log > NUL 
if "!errorlevel!"=="0" 
( echo "OK" )
else ( echo "NOK" )