且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在文件名中查找字符串

更新时间:2022-05-07 22:26:58

您可以简单地使用包含account的通配符.

You can simply use the wildcard that includes account.

FOR /R %completepath% %%G IN (*account*.csv) DO (
  echo %%~nG
)

如果您仍然需要处理所有* .csv文件并另外重命名名称中带有"account"的文件,那么可以通过以下方法进行检查:

If you still need to process all *.csv files and additionally rename those, that have 'account' in their names, then here's how you could check that:

FOR /R %completepath% %%G IN (*.csv) DO call :process "%%~nG"
GOTO :EOF

:process
SET %name%=%~1
SET chkname=%name:*account=?%
IF "%chkname:~0,1%"=="?" (
  ECHO %name% -- this is account file!
) ELSE (
  ECHO %name% -- this is NOT account file
)