batch file - Getting a for loop working -
i'm trying split apart system path variable batch. have:
@echo off setlocal enabledelayedexpansion set npath=%path% set i=0 echo %npath% > temp /f "delims=;" %%a in (temp) ( echo [!i!]: %%a set /a i=!i!+1 )
when runs, however, runs loop single time. instead of expected output, list of directories in path, outputs single one:
what's happening? doing wrong? i've tried using path string, i've tried changing number of tokens, i've tried everything. not understand how loops work in batch?
try iterate items in path plain loop (and need set quotes prevent space collisions):
@echo off setlocal enabledelayedexpansion set "_path="!path:;=" "!"" rem echo %_path% set i=0 %%a in (%_path%) ( echo [!i!]: %%~a set /a i=!i!+1 ) endlocal
Comments
Post a Comment