Saved Bookmarks
| 1. |
Solve : Change directory dynamically and start application, using Loop? |
|
Answer» Hi i'm NEW here. cd "C:\TESTING\CROP - 001" portion of my code here: Code: [Select]for /L %%x in (1,1,10) do ( IF %%x LSS 10 Set curInstancePath="C:\TESTING\CROP - 00%%x" IF %%x GTR 9 Set curInstancePath="C:\TESTING\CROP - 0%%x" echo %curInstancePath% cd %curInstancePath% start testing.exe ) For this, echo %curInstancePath%, why i always get the value "C:\TESTING\CROP - 010"? Pls advice..really appreciate your helps..Code: [Select]REM PUT THIS AT START OF BATCH setlocal enableextensions enabledelayedexpansion for /L %%x in (1,1,10) do ( if %%x LSS 10 Set curInstancePath="C:\TESTING\CROP - 00%%x" if %%x GTR 9 Set curInstancePath="C:\TESTING\CROP - 0%%x" REM In loop must use delayed expansion to read env variables REM because otherwise they are expanded before loop is run REM use !VARNAME! instead of %varname% echo !curInstancePath! cd !curInstancePath! start testing.exe ) thanks alot Contrex. but i face another problem.. cd !curInstancePath! is not working i check the current directory by using echo %cd% i couldn't see any changes of directory. once again..thanks for your helps..Do those directories already exist?Quote from: sayhigh on May 30, 2007, 07:55:40 PM thanks alot Contrex. is curInstancePath taking the right value each time? yes..it get the right value each time.. i've solved it by add C: for /L %%x in (%curInstance%,1,%curMaxInstance%) do ( IF %%x LSS 10 Set curInstancePath="C:\Stress Tester\CROP - 00%%x" IF %%x GTR 9 Set curInstancePath="C:\Stress Tester\CROP - 0%%x" cd !curInstancePath! C: ) thanks alot..Oh I see you are not logged in on C: You can do the same thing another way by adding the /D switch to the CD command. Code: [Select]cd /D !curInstancePath! Code: [Select]F:\>cd c:\batch F:\> F:\>cd /D c:\batch C:\batch> sorry..previously i forget to mention i run the bat file in D drive.. yeah..thanks alot man.. |
|