从原始字符串批处理脚本查找多个字符串匹配
我目前在文件夹中有一个文件列表,我需要迭代并排除与模式匹配的非生产文件。如何在批处理命令中搜索多个字符串?
例如,我将文件作为
- 每个
- 具有
- “
- ”
- ude
- dev
- QA_TEST_1.TXT QA_809_TEST.TXT DEV_93439_SD.TXT STG_ABC_ABC_SLDKF_TXT
- qa
”一词的文件, STG”并生成一个没有它们的文件列表 - 这是
- prod_4845_sdfd.txt
- prod_998_sdfd.txt
- live_lskd_sd3434.txt
- xyz_sdfdf_s3rer.txtt
,问题是 - 我无法找到任何批量的pressert pressivalents equialtings。 Findstr仅适用于一个字符串,因此我无法实现该工作。这是我有的代码
set i=0
for /F "delims=" %%a in ('dir /B /A /S Path *.txt') do (
set /A i+=1
rem put the file names in array
set list[!i!]=%%~na
rem try to find the file names
echo %%~na|find "dev" or "qa" or "stg" >nul
if errorlevel 1 (echo notfound) else (echo found %%~na )
)
I currently have a list of files in a folder that i need to iterate through and exclude the non production files that matches the pattern. how do i search for multiple strings in a batch command?
for example i have files as
- QA_test_1.txt
- QA_809_test.txt
- dev_93439_sd.txt
- stg_abc_sldkf_df.txt
- prod_4845_sdfd.txt
- prod_998_sdfd.txt
- live_lskd_sd3434.txt
- xyz_sdfdf_s3rer.txt
from the list above i need to exclude every file that has the word "dev", QA "Stg" and generate a list of files without them - which is
- prod_4845_sdfd.txt
- prod_998_sdfd.txt
- live_lskd_sd3434.txt
- xyz_sdfdf_s3rer.txt
The problem is - i am not able to find any batch command that can do a grep equivalent for multiple strings. FindStr does it only for one string and hence i am not able to get that working. here is code that i have
set i=0
for /F "delims=" %%a in ('dir /B /A /S Path *.txt') do (
set /A i+=1
rem put the file names in array
set list[!i!]=%%~na
rem try to find the file names
echo %%~na|find "dev" or "qa" or "stg" >nul
if errorlevel 1 (echo notfound) else (echo found %%~na )
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢您的所有回应。
我能够在下面做
Thank you for all the response.
I was able to do it below way