下面将回显文件中的每一行C:\scripts\testFile.txt。空行将不被处理。
for /F "tokens=*" %%A in (C:\scripts\testFile.txt) do ( echo %%A rem do other stuff here )
更高级的示例显示,如何在FOR循环中从受限制的文件集数据派生出的数据可用于重定向批处理执行,同时将搜索到的内容保存到文件中:
@echo off setlocal enabledelayedexpansion for /f %%i in ('dir "%temp%\test*.log" /o:-d /t:w /b') do ( set "last=%temp%\%%i" type !last! | find /n /i "Completed" >nul 2>&1 >> %temp%\Completed.log ^ && (echo Found in log %%i & goto :end) || (echo Not found in log %%i & set "result=1")) :: add user tasks code here if defined result echo Performing user tasks... :end echo All tasks completed exit /b
请注意,命令字符串分成多行代码的时间,命令组由括号分隔。