CD command not working inside FOR loop?
我是批编程新手。
下列程序的输出:
1 2 3 4 5 6 7 8 9 10 11 12 | @ECHO OFF cd /d C:%HOMEPATH%\AppData oaming\Mozilla\Firefox\Profiles echo %cd% FOR /F %%i IN (temp_list.txt) DO ( echo i is %%i cd folder echo %cd% ) cd folder echo %cd% pause |
是:
1 2 3 4 5 6 7 8 9 10 11 12 13 | C:\Users\arnab\AppData oaming\Mozilla\Firefox\Profiles i is e6slask2.default C:\Users\arnab\AppData oaming\Mozilla\Firefox\Profiles i is random.default The system cannot find the path specified. C:\Users\arnab\AppData oaming\Mozilla\Firefox\Profiles The system cannot find the path specified. C:\Users\arnab\AppData oaming\Mozilla\Firefox\Profiles\folder Press any key to continue . . . |
我知道
oaming\Mozilla\Firefox\Profiles\folder"
首先,批处理不更新代码块内的变量,但必须有解决方法。这就是为什么当使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | @ECHO OFF Setlocal EnableDelayedExpansion cd /d C:%HOMEPATH%\AppData oaming\Mozilla\Firefox\Profiles echo %cd% FOR /F %%i IN (temp_list.txt) DO ( echo i is %%i cd folder echo !cd! ) cd folder echo %cd% pause |
用感叹号代替百分号(