how to use batch file variable outside inner for loop

前端 未结 1 437
长发绾君心
长发绾君心 2021-01-26 12:55

I am not familiar with batch script variable scoping. But I ran into scoping problem due to my lack of batch script experience.

for /f %%i in (\'dir /s /b \"%Fol         


        
相关标签:
1条回答
  • 2021-01-26 13:33

    Again, EnableDelayedExpansion:

    setlocal enabledelayedexpansion
    
    for /f %%i in ('dir /s /b "%FolderLocation%"') do (
    For %%A in ("%%~i") do (
    Set File=%%~nxA
    echo !File!
    )
    :: This shows how "%" doesn't work but "!" does
    Echo ^%File^%: %File%   -   ^!File^!: !File!
    )
    

    And that should work for you. Just remember to use !File! inside a for-loop and %File% outside.

    0 讨论(0)
提交回复
热议问题