批处理文件的文件夹检测 [英] Batch File folder detection
问题描述
是的,我知道我需要双击了一个%是一个%%在批处理文件中使用时。 ;)
Yes, I know I need to double-up the %a to be %%a when used in a batch file. ;)
这工作,但不给我我想要的结果 - 这仅仅是太多了。
This works, but does not give me the results I want - this is just too much..
FOR /f %a IN ('dir "D:\tomcat*" /ad /b ') DO FOR /f %b IN ('dir "D:\%a\webapps" /ad /b ') DO ECHO D:\%a\webapps\%b
我真的很想做的是:
What I would really like to do is:
FOR /f %a IN ('dir "D:\tomcat*\webapps" /ad /b ') DO ECHO %a
不过,我得到的结果错误:
But, I get the resulting error:
文件名,目录名或卷标语法不正确。
The filename, directory name, or volume label syntax is incorrect.
我想做到这一点,因为我有一个需要检测的文件夹中都有Tomcat和可以是任何如下:
I would like to do this as I have a need to detect which folders have tomcat in them and could be any of the following:
D:\tomcat
D:\tomcat1
D:\tomcat2
D:\tomcat_1
etc.
谢谢!
推荐答案
通配符(?
和 *
)可用只有在使用的的最后的路径的项目,所以你必须要解决的。
Wildcards (?
and *
) can only be used in the last item of a path, so you will have to work around that.
至于嵌套的为
的替代方法循环您正在使用,你也可以做到以下几点:
As an alternative method to the nested for
loops you are using, you could also do the following:
for /F "eol=| delims=" %A in ('dir /A:D /B "D:\tomcat*"') do (> nul 2>&1 dir /A:D "%~A\webapps" && echo "%~A")
这个输出的名称中包含的tomcat
在其名称中的和所有文件夹的已经得到了一个名为的子目录的webapps
。
This outputs all folders whose names contain tomcat
in their names and have got a subdirectory called webapps
.
您需要提供选项字符串EOL = | delims =
为 FOR / F
;这也适用于与两个嵌套为
循环变体。
You need to provide the option string "eol=| delims="
for for /F
; this also applies to the variant with the two nested for
loops.
这篇关于批处理文件的文件夹检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!