Windows批处理嵌套循环问题
我需要逐行读取外部循环中的文件,获取该值并在内部循环中使用它。但目前我能够从这个文件中读取第一行,并在内部循环中执行一些必需的处理,但外部循环只运行一次 为什么外部循环只运行一次 myfile.txt包含: AWC00201Windows批处理嵌套循环问题,windows,batch-file,Windows,Batch File,我需要逐行读取外部循环中的文件,获取该值并在内部循环中使用它。但目前我能够从这个文件中读取第一行,并在内部循环中执行一些必需的处理,但外部循环只运行一次 为什么外部循环只运行一次 myfile.txt包含: AWC00201 AWC00202 AWC00203 DDDD 我得到以下输出: ECHO is off. AWC00201 After Nested For AWC00201 ECHO is off. Most recent subfolder: 20141103_170658_wro_a
AWC00202
AWC00203
DDDD 我得到以下输出:
ECHO is off.
AWC00201
After Nested For
AWC00201
ECHO is off.
Most recent subfolder: 20141103_170658_wro_awc
%D
____________ TOOLING.REPORT: 0
ECHO is off.
notfound
ECHO is off.
now go up
AWC00201
AWC00201
Press any key to continue . . .
您的代码有一个大问题,需要更改一件事 问题在于,在
for
循环中使用goto
并保持循环迭代是不可能的goto
取消循环的
要改变的是变量的使用。您在可替换参数的中有所需的信息。使用它们。当可替换参数不能提供所需的值时,将该值移动到变量,但实际情况并非如此
@echo off
setlocal enableextensions disabledelayedexpansion
for /F "delims=" %%D in (myfile.txt) do (
cd /d "s:\@vantage\AFG\AWC\AWCU\simulation\WRO_Regression_results\%%D"
for /d %%a in (.) do echo Current folder is "%%~fa"
set "file="
FOR /F "delims=" %%i IN ('dir /b /ad-h /o-d 2 >nul ') DO if not defined file (
set "file=1"
echo subfolder found : %%i
find /c "O K" ".\%%i\tooling.report" >nul 2>nul
if errorlevel 1 (
echo O K found
) else (
echo O K not found or file does not exist
)
)
if not defined file (
echo subfolder not found
)
)
pause
你不能用powershell吗?它运行在所有现代Windows操作系统上,使这些东西更加优雅。听起来不错,但只是因为缺少时间,我需要尽快完成这项任务。但好主意,谢谢。也许你是对的,我会试试,让你知道结果。非常感谢。
@echo off
setlocal enableextensions disabledelayedexpansion
for /F "delims=" %%D in (myfile.txt) do (
cd /d "s:\@vantage\AFG\AWC\AWCU\simulation\WRO_Regression_results\%%D"
for /d %%a in (.) do echo Current folder is "%%~fa"
set "file="
FOR /F "delims=" %%i IN ('dir /b /ad-h /o-d 2 >nul ') DO if not defined file (
set "file=1"
echo subfolder found : %%i
find /c "O K" ".\%%i\tooling.report" >nul 2>nul
if errorlevel 1 (
echo O K found
) else (
echo O K not found or file does not exist
)
)
if not defined file (
echo subfolder not found
)
)
pause