8 Aug 2009 17:34
Re: process the list in reverse order in batch file
You can always reverse the original string, and then process the reversed
string front to back for what you need to accomplish. Sample code which
will reverse a comma separated string is:
setlocal ENABLEDELAYEDEXPANSION
set foo=one,two,three,four
set revFoo=
set commaAdder=
:reverseLoop
for /F "tokens=1,* delims=," %%p in ("!foo!") do (set
revFoo=%%p!commaAdder!!revFoo!&set foo=%%q&set commaAdder=,)
if not "!foo!" == "" goto :reverseLoop
echo foo is !foo!
echo revFoo is !revFoo!
In order to better debug your batch code, I recommend using Running Steps.
The batch debugger from Stepping Software (http://www.steppingsoftware.com).
It has a code analyzer which provides you with errors and warnings even
before you start executing, plus you can step through your code, watch
variables, etc.
Good Luck
GISkier
--
--
View this message in context: http://www.nabble.com/process-the-list-in-reverse-order-in-batch-file-tp24846264p24877981.html
(Continue reading)
RSS Feed