![]() ![]() This can be avoided by additional SETLOCAL: for /D %%G in (*) do ( Note that delayed expansion occurs after FOR variable expansion, so the result will be corrupted if %%G constains !. ![]() The following code using delayed expansion will give the result you seek: off Note that delayed expansion requires delayed expansion to be enabled via SETLOCAL EnableDelayedExpansion Most parsing has completed by now -Ģ) FOR variable expansion: for %%A in (*) do echo %%Aģ) Delayed environment variable expansion: echo !var!Ĥ) CALL % expansion - Parameter: call echo %%1 or Environment variable: call echo %%var%%ĥ) SET /A environment variable expansion: `set /a "value=var+1" It is all explained in the link, but in summary, the order of expansion is:ġ) % expansion - Parameter: echo %1 or Environment variable: echo %var% There are multiple points where various types of variables are expanded, and you must fully understand them if you truly want to make the most of batch programming. The CMD processor is a complicated beast (and also poorly documented). Your logic is wrong - the assignment of _newp should be based on the value of _srcp The solution is delayed expansion, which occurs as each command within the loop is being executed. So the value is the value that existed before the loop was started. %var% expansion occurs when the statement is parsed, and the entire parenthesized code block is parsed in one pass, before any commands are executed. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |