简短版本:我的脚本可让您输入一些内容和数字,然后查找该文件。简单。现在我希望你输入一堆数字,脚本将查找包含任何这些数字的文件。我理解如何使用多个字符串执行此操作,但脚本变得混乱。
这是我在寻找一个文件时得到的。
@echo off
SETLOCAL ENABLEEXTENSIONS
set /p "example1"=blabla: "
set /p "example2"=blabla: "
set /p "Number=Number: "
Echo Will search for : %example1%example2%%number%.pdf
for /R "my location" %%a in (%example1%example2%%number%.pdf) do (
blablabla
)
这很有效。添加多个%number会使它看起来像我现在这样做......
@echo off
SETLOCAL ENABLEEXTENSIONS
set /p "example1"=blabla: "
set /p "example2"=blabla: "
set /p "Number1=Number: "
IF [%Number1%] EQU [] echo Moving to next step & goto Next_step
set /p "Number2=Number: "
IF [%Number2%] EQU [] echo Moving to next step & goto Next_step
set /p "Number3=Number: "
IF [%Number3%] EQU [] echo Moving to next step & goto Next_step
:next step REM Here comes the messy part
Echo Will search for : %example1%%example2%%number1%.pdf
Echo Will search for : %example1%%example2%%number2%.pdf
Echo Will search for : %example1%%example2%%number3%.pdf
for /R "my location" %%a in (%example1%%example2%%number1%.pdf) do (
blablabla
)
for /R "my location" %%a in (%example1%%example2%%number2%.pdf) do (
blablabla
)
for /R "my location" %%a in (%example1%%example2%%number3%.pdf) do (
blablabla
)
关于问题:如何总结所有%number??%
输入/变量并使用这样的字符串
for /R "my location" %%aa in (%example1%%example2%%AllNumbers%.pdf do (
blablabla
)
我已经尝试了<%>!%any%!,但我不确定我是否可以像我想的那样使用它。如果它甚至可能这就是我尝试过的(以及其中的一些变体):
rem this is right after all the set /p's shown in the example
Set AllNumbers=!%number1%%number2%%number3%!
Echo Will search for : %example1%%example2%%AllNumbers%.pdf
for /R "my location" %%aa in (%example1%%example2%%AllNumbers%.pdf do (
blablabla
)
@npocmaka - 感谢您的帮助。检查下面的编辑。这是我的结果。我希望它找到我输入的所有四个文件,但它只找到了第一个。
最终修改:如果要删除/L
答案 0 :(得分:2)
set number
您可以列出以number
开头的所有变量:
@echo off
SETLOCAL ENABLEEXTENSIONS
set "example1"=example"
set "example2"=example"
set "Number1=1"
set "Number2=2"
set "Number3=3"
for /f %%# "tokens=2 delims==" in ('set number') do (
for /R "my location" %%a in (*%example1%%example2%%%#.pdf) do (
blablabla
)
)
或者您可以使用FOR /L
:
for /l %%# in (1 ; 1 ; 3) do (
for /R "my location" %%a in (*%example1%%example2%%%#.pdf) do (
blablabla
)
)
您可以使用 plain FOR :
迭代一组数字for %%# in ( 2 4 12 ) do (
for /R "my location" %%a in (*%example1%%example2%%%#.pdf) do (
blablabla
)
)
或
for %%# in ( %number1% %number2% %number3% ) do (
for /R "my location" %%a in (*%example1%%example2%%%#.pdf) do (
blablabla
)
)
答案 1 :(得分:2)
更简单的方法:
@echo off
set /p "example1=blabla: "
set /p "example2=blabla: "
set /p "Numbers=Enter all numbers separated by space: "
for %%n in (%Numbers%) do (
Echo Will search for : %example1%%example2%%%n.pdf
for /R "my location" %%a in (%example1%%example2%%%n.pdf) do (
blablabla
)
)