home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,531 of 68,980   
   Herbert Kleebauer to Mark Ise   
   Re: for-loop cannot process braces   
   05 May 20 22:47:48   
   
   From: klee@unibwm.de   
      
   On 05.05.2020 16:17, Mark Ise wrote:   
      
   >>> The code:   
   >>>   
   >>> for %%i in (%*) do (   
   >>> 	echo hallo   
   >>>  )   
   >>>   
   >>> Alternative:   
   >>> for %%i in ("%*") do (   
   >>>   
   >>> The problem:   
   >>> If arguments contain braces without spaces, the first version fails. The   
   >>> cmd-window closes without an error message.   
      
      
   > Usually I put the files by drag n drop to the batch. Therefore I have   
   > made a test with three files and a test-batch: echo %*   
   >   
   > The output is:   
   >   
   > echo "F:\z2\Test1 ().txt" F:\z2\Test2().txt F:\z2\Test3.txt   
   > "F:\z2\Test1 ().txt" F:\z2\Test2().txt F:\z2\Test3.txt   
      
   You can first copy %* to %x%, using a single "" for each parameter   
   and then use  %x% instead of %* in the for loop:   
      
   @echo off   
      
   call :sub "F:\z2\Test1 ().txt" F:\z2\Test2().txt F:\z2\Test3.txt   
   goto :eof   
      
   :sub   
   set x=   
   :loop   
   if [%1]==[] goto :end   
   set x=%x% "%~1"   
   shift   
   goto :loop   
   :end   
      
   for %%i in (%x%) do (   
   	echo %%i   
     )   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca