批处理文件循环 - 跳过文件,如果文件名包含字符串

Batch File Loop - Skip file, if file name contains string

我正在尝试做与 this question 基本相同的事情,即我想遍历目录中的文件,但排除名称中包含特定字符串的文件(在我的例子中是“.new ”。但是,问题是我正在使用

setlocal DisableDelayedExpansion

因为我希望批处理也能处理包含感叹号的文件名。因此,我尝试直接使用循环变量 %%x 而不是新变量来使解决方案起作用,但这似乎不起作用:

setlocal DisableDelayedExpansion
For %%x in (*.mkv *.mp4) do (
  If "%%x" == "%%x:.new." (
    Echo Skipped "%%x"
  ) Else (
    Echo Processing "%%x"
  )
)

字符串匹配不起作用,即我得到

Processing "file.mkv"    
Processing "file.new.mkv"

任何关于如何让它工作的提示都将不胜感激;谢谢!

批处理 string-manipulation 命令不能像 %%x.

一样直接应用于 metavariables
echo %%x|findstr /i /L ".new.">nul
if errorlevel 1 (
 echo process %%x
) else (
 echo skip %%x
)

应该对你有用,从字面上找到字符串 .new. /l/i case-insensitive。如果找到,则将 errorlevel 设置为 0,否则设置为非 0。