我有一个文件“codes.txt”,每行包含一个代码。
我试图在文件夹中搜索和重命名名称中包含代码的所有文件,以及另一个字符串:
@echo off
for /F "tokens=*" %%b in (codes.txt) do (
// If file names in folder contain %%b and "foo", rename to %%b.'string'
// If file names in folder contain %%b and "foo2", rename %%b.'string2'
)
谢谢
假设文件`codes 包含:
1234
5678
并且您的目录有一个名为:
foo1234.txt
1234ABCfoo.txt
5678.txt
然后这个脚本会做:
@echo off
for /f %%i in (codes.txt) do (
for /f %%a in ('dir /b /a-d *%%i* ^| findstr "foo"') do echo %%a
)
首先它循环通过codes.txt,使用换行符作为分隔符。然后它会在包含代码的文件上做一个目录,并findstr
在名称的任何地方做一个for foo。使用上述文件,它将回显找到的唯一 2 个匹配项:
foo1234.txt
1234ABCfoo.txt
它不会匹配,5678.txt
因为它foo
在名称中没有任何位置。
显然,您需要将echo
我脚本中的部分更改为您想要实现的命令。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句