简体   繁体   English

批处理Windows 7:循环读取文本文件

[英]batch windows 7: loop to read a text file

I have a text file like that: 我有一个像这样的文本文件:

info1 subinfo1 info1子信息1

info2 subinfo2 info2子信息2

info3 subinfo3 info3子信息3

I have to perform a loop on command using these infos. 我必须使用这些信息在命令上执行循环。 I do it like that: 我这样做:

for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
        set stack=%%a
        set orientation=%%b 
        command1 -i test -o test -option1 %stack% -option2 %orientation%
)

It doesn't work. 没用 the option are always the same. 选项始终相同。

and Indeed if I do: 确实,如果我这样做:

for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
set stack=%%a
set orientation=%%b   
echo %%a
echo %%b
echo %stack%
echo %orientation%
)

I have this: 我有这个:

info1_lr info1_lr

axial 轴向的

info2_lr info2_lr

sagittal 矢状

info3_lr info3_lr

coronal

info2_lr info2_lr

sagittal 矢状

info2_lr info2_lr

sagittal 矢状

info2_lr info2_lr

sagittal 矢状

Is that normal ? 那正常吗?

Yes. 是。 Absolutely. 绝对。

Please use the search facility to find out about delayed expansion on Stack Overflow. 请使用搜索工具查找有关Stack Overflow delayed expansion信息。 The reasoning and solution will be there - it's a question that's been answered hundreds of times. 推理和解决方案就在那里-这个问题已经被回答了数百次。

so here is how I did: 所以这是我的做法:

    for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
        setlocal enabledelayedexpansion
        set stack=%%a
        set orientation=%%b 
        echo %%a
        echo %%b
        echo !stack!
        echo !orientation!
        endlocal
)

after looking at delayed expression and it almost works for me. 在看了延迟的表情之后,它几乎对我有用。

except that I have a conflict with a way to "increment" a variable: 除了我与“增加”变量的方式存在冲突之外:

set cmdIntensityNLM=%cmdIntensityNLM% -i %RESULTS%/!stack!_blabla_%ITER%.nii.gz -o %RESULTS%/!stack!_blabla_%ITER%.nii.gz

I add to change it to: 我添加将其更改为:

set cmdIntensityNLM=!cmdIntensityNLM! -i %RESULTS%/!stack!_blabla_%ITER%.nii.gz -o %RESULTS%/!stack!_blabla_%ITER%.nii.gz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM