| 1. |
Solve : Batch 'For' Problem? |
|
Answer» Hi everyone, I was under the assumption I had to state what I want taken / read from the .txt file. Wrong? Depends. If you want the whole line, use "tokens=" Tried it, doesn't make a difference. Have you tried leaving echo on and watching to see how the variables expand? here's the output: dir /ad /b d:\*.* 1>d:\temp\test.txt set drvpath=C:\Windows\inf setlocal ENABLEDELAYEDEXPANSION for /F "tokens=" %x in (d:\temp\test.txt) do (set drvpath=!drvpath!;c:\windows\s upport\drivers\%x ) endlocal del d:\temp\test.txt set drvpath drvpath=C:\Windows\inf As you can see they don't expand at all I'm not bound to that way either. If one of you can point me in the right direction I'm just trying to accomplish this: list of folders > registry key in the form of folder1;folder2;folder3 and so on.1. Move Setlocal Enabledelayedexpansion to before you set drvpath. 2. Remove Endlocal. 3. The "tokens=1" ensures that if a line in the text file has spaces, you will only capture up to the FIRST space. THANKS A LOT FOR YOUR HELP!!! This is how it works in the end: setlocal ENABLEDELAYEDEXPANSION dir /ad /b d:\vms > d:\temp\test.txt set drvpath=%systemroot%\inf for /f "tokens=*" %%x in ( d:\temp\test.txt ) do ( set drvpath=!drvpath!;c:\windows\support\drivers\%%x ) set drvpath Quote set drvpath this is more usual Code: [Select]echo %drvpath% But that's just a stylistic thing. Glad it works. By the way, you do know that you can avoid using a temp file? Use for /f and enclose a command in single quotes, and the command output will be PARSED, line by line, as if it was in a file. And put the loop on one line? Code: [Select]setlocal enabledelayedexpansion set drvpath=%systemroot%\inf for /f "tokens=*" %%x in ('dir /ad /b d:\vms') do set drvpath=!drvpath!;c:\windows\support\drivers\%%x echo drvpath=%drvpath% |
|