Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理:如果变量包含单词,则转到EOF_Batch File - Fatal编程技术网

Batch file 批处理:如果变量包含单词,则转到EOF

Batch file 批处理:如果变量包含单词,则转到EOF,batch-file,Batch File,我有一个批处理脚本,它有一个变量“%4”,它是随机文件名,但有时它有如下名称: some.thing.here.mp3 some.other.thing.mp3 and.another.mp3 and.some.file.mp3 如果文件名包含单词“some”,我想让它转到EOF(所以除了第三个文件外,所有文件都是…) 到目前为止我有这个,但它不起作用 IF /I "%4"=="some" GOTO EOF 试试这个: echo "%4" | find /i "some" >nul 2

我有一个批处理脚本,它有一个变量“%4”,它是随机文件名,但有时它有如下名称:

some.thing.here.mp3
some.other.thing.mp3
and.another.mp3
and.some.file.mp3
如果文件名包含单词“some”,我想让它转到EOF(所以除了第三个文件外,所有文件都是…)

到目前为止我有这个,但它不起作用

IF /I "%4"=="some" GOTO EOF
试试这个:

echo "%4" | find /i "some" >nul 2>&1 && GOTO:EOF

将批处理文件发布到目前为止。这样测试比较容易。我猜你只需要使用find或findstras一个附带问题我可以包含多个单词吗?像“someORotherORfoobar”?是的,但是
find
查找每个单词。因此,将搜索模式放入变量
set“var=some”
echo“%4”;find/i“%var%”
示例:
echo“%4”;findstr/i“some test”
,有关更多单词,请使用
findstr
。我遇到了一个问题,我正在使用下面的代码在%4中查找单词“test”(这通常是我第一篇文章中的文件名),但当将代码更改为%5(这是一个文件夹完整路径,例如“c:\temp\some.test.folder”)时,它不会接收到它。。这段代码对文件夹不会像对文件一样有效吗?回显“%~5”|查找/i”测试“>nul 2>&1&&GOTO end