--这些是要求:
echo)。我尝试过的(只适用于一个通配符):
SET wildcard=a*.txt
cd c:\somedirectory
IF EXIST "%wildcard%" (
REM PROCESS THE FILES
) ELSE (
ECHO There are no files that match that wildcard, please review.
)这显然只有在通配符是唯一的情况下才有效。
我尝试过的:
SET wildcard=a*.txt b*.txt
cd c:\somedirectory
FOR %%A IN (%wildcard%) DO (
ECHO %%A
)这将打印与a*.txt或b*.txt匹配的文件。我不希望这种扩大发生。我需要实际的通配符值才能进入循环。
通过展开,我不能告诉用户他的一些通配符没有文件。这里有a*.txt文件,但没有b*.txt文件。我要告诉用户。类似于:
a*.txt:有文件。 b*.txt:没有文件,请查看。
类似的东西(这不起作用,只是我想要找什么):
SET wildcard=a*.txt b*.txt c*.txt
cd c:\somedirectory
REM loop on the wildcards
FOR %%A IN (%wildcard%) DO (
REM verify if there are files for that wildcard
IF EXIST %%A (
REM loop on the files from the specific wildcard
FOR %%F IN (%%A) DO (
REM PROCESS THE FILES
)
) ELSE (
ECHO This pattern %%A has no files associated
)
)基本上,我能阻止%wildcard%中的值在IF语句中的扩展吗?
关于@double beep的评论:
IF EXIST语句的想法正是我想要的,但我不知道用户需要多少通配符。
设置wildcard=a*.txt b*.txt ..。如果存在a*.txt (.),这是可以的。如果存在b*.txt (.).但是,根据用户在wilcard变量中放入的内容,如何实现这种灵活性呢?我想在通配符的值上循环,但是对于展开,我不想要。
发布于 2019-03-11 17:10:45
使用带有参数的call (不解析通配符)的这段代码怎么样:
@echo off
set "WildCard=a*.txt b*.txt *.vi"
call :LOOP %WildCard%
rem ...
goto :EOF
:LOOP
if "%~1"=="" goto :EOF
if exist "%~1" echo There are files that match the pattern: "%~1"
shift /0
goto :LOOPhttps://stackoverflow.com/questions/55104569
复制相似问题