为什么!做!不要在FOR循环内扩展到它的值?
setlocal EnableDelayedExpansion
FOR /F "delims=" %%I in ('dir /b /ad /s') do (
pushd "%%~I"
set doit=yes
if not exist *.f* (
if not exist *.c* set doit=no
)
if "!doit!" == "yes" FOR /F "delims=" %%G IN ('DIR *.f* *.c* /B /A:-D /O:D') DO SET NewestFile=%%G
popd
)
当我跑这个时,我看到了!doit!没有扩大:
...
如果“!doit!” ==“是”FOR / F“delims =”%G IN('DIR .f .c / B / A:-D / O:D')DO SET NewestFile =%G
...