Search code examples
windowsbatch-filecmdxcopy

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


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.

Please help thank you


Solution

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