我现在使用这一行:
IF EXIST "%SystemDrive%\Arkey5" (ECHO Found "%SystemDrive%\Arkey5" >> "LOG.txt" 2>&1) ELSE IF EXIST "D:\Arkey5" (ECHO Found "D:\Arkey5" >> "LOG.txt" 2>&1) ELSE ECHO NOTHING FOUND >> "LOG.txt" 2>&1
这几乎是完美的,只是错过了这一件事, 如果两个目录都存在,我就不会写一个日志行...... 所以此时此刻只有: 01."%SystemDrive%\ Arkey5"存在 02." D:\ arkey5"存在 03. ELSE(都缺失)
答案 0 :(得分:4)
set found=
for %%F in (
"%SystemDrive%\Arkey5\"
"D:\Arkey5\"
) do if exist %%F (echo Found %%F >>"log.txt" & set found=1)
if not defined found echo NOTHING FOUND >>"log.txt"
在每个路径的末尾添加\
以确保IF EXIST仅匹配目录。