giskier | 8 Aug 17:34 2009

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)

foxidrive | 8 Aug 17:51 2009
Picon

Re: process the list in reverse order in batch file


Be careful with the URLs below - I don't think nabble.com it affiliated
with batchworld at all.  They could be links with malware exploits.

On Sat, 8 Aug 2009 08:34:56 -0700 (PDT), giskier
<gonzaloi@...> wrote:

>
>In order to better debug your batch code, I recommend using Running Steps. 
>The batch debugger from Stepping Software (http://www.steppingsoftware0.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-tp24846264p248779810.html
>Sent from the Batch World mailing list archive at Nabble.com.

------------------------------------

To Post a message, send it to:   batchworld@...

To Unsubscribe, send a blank message to:
batchworld-unsubscribe@...! Groups Links

<*> To visit your group on the web, go to:
(Continue reading)

Theodorik OBroin | 8 Aug 19:27 2009
Picon

Re: process the list in reverse order in batch file

Cheers mate ;o)

2009/8/8 foxidrive <foxidrive@...>

>
>
>
> Be careful with the URLs below - I don't think nabble.com it affiliated
> with batchworld at all. They could be links with malware exploits.
>
>
> On Sat, 8 Aug 2009 08:34:56 -0700 (PDT), giskier
> <gonzaloi@...
<gonzaloi%40steppingsoftware.com>> wrote:
>
> >
> >In order to better debug your batch code, I recommend using Running Steps.
>
> >The batch debugger from Stepping Software (
> http://www.steppingsoftware0.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:
(Continue reading)

giskier | 8 Aug 22:28 2009

Re: process the list in reverse order in batch file


You can use a command in the form

for /f %p in (myfile.txt) do call :ProcessLine %p
goto :EOF

:ProcessLine
rem Add code here to reverse the line (which is %* since its used as
parameter in the call), and do all the processing you need here.

Good Luck

GISkier

PS. If you don't trust the llink I sent, which is not malicious, just do a
web search for "Running Steps debugger"  and you will find this tool.  It
will be very helpful.

Raagu wrote:
> 
> Hello Thanks for wonderful reply. It worked fine..
> But I have to execute this for loop multiple times and d number of times
> determined by number files in a text file..
> 
> 
> Here is the my snippet
> 
> key=dependencies
> for /f %%f in (myBuild\modules.txt) do (
> 
(Continue reading)

giskier | 9 Aug 17:12 2009

Re: process the list in reverse order in batch file


In your code to process each line you add the following (which will take the
first five letters of the variable and compare to zero. (including period)). 
As you can see, if the comparison matches it jumps over the processing and
returns without doing anything.

:ProcessLine
if /I "%reversefoo:~0,5" == "zero."  goto :EndProcessLine
...
do processing stuff here
...
:EndProcessLine
goto :EOF

The last line (goto :EOF) is the return statement assuming you got to
ProcessLine using "call :ProcessLine ....etc...".   You can also return
using "exit /B  X"  where X is a number.  If you use this approach, upon
returning %errorlevel% will be set to X.

I hope this helps.  Check the website for Stepping Software.  You will find
multiple interesting articles on interesting techniques to be applied in
batch files.  Plus the best batch file debugger: Running Steps 1.1.

Good Luck.

GISkier

Raagu wrote:
> 
> Thanks giskier... Your code worked fine.. [:)]
(Continue reading)

giskier | 9 Aug 17:14 2009

Re: process the list in reverse order in batch file


The link is not malicious.  I am simply informing you of a great tool for
batch files in a forum for batch files.  If you don't want to click, just do
a search on "Running Steps Debugger".  You will find the same information I
am giving you here.

GISkier

Theodorik OBroin wrote:
> 
> Cheers mate ;o)
> 
> 2009/8/8 foxidrive <foxidrive@...>
> 
>>
>>
>>
>> Be careful with the URLs below - I don't think nabble.com it affiliated
>> with batchworld at all. They could be links with malware exploits.
>>
>>
>> On Sat, 8 Aug 2009 08:34:56 -0700 (PDT), giskier
>> <gonzaloi@...
<gonzaloi%40steppingsoftware.com>> wrote:
>>
>> >
>> >In order to better debug your batch code, I recommend using Running
>> Steps.
>>
>> >The batch debugger from Stepping Software (
(Continue reading)

foxidrive | 9 Aug 17:59 2009
Picon

Running Steps Debugger

On Sun, 9 Aug 2009 08:14:26 -0700 (PDT), giskier
<gonzaloi@...> wrote:

>
>The link is not malicious.  I am simply informing you of a great tool for
>batch files in a forum for batch files.  If you don't want to click, just do
>a search on "Running Steps Debugger".  You will find the same information I
>am giving you here.
>
>GISkier

How are these posts getting to batchworld?  Are you gating them yourself?
Do you have permission from Yahoo or the moderator?

I would welcome such an arrangement where the original posts arrive here as
well, but seeing *only* your followups and the text below made me very
suspcious.

>>> >View this message in context:
>>> http://www.nabble.com/process-the-list-in-reverse-order-in-batch-file-tp24846264p248779810.html
>>> >Sent from the Batch World mailing list archive at Nabble.com.

This isn't Nabble.com and only your user name is on these posts...

------------------------------------

To Post a message, send it to:   batchworld@...

To Unsubscribe, send a blank message to:
batchworld-unsubscribe@...! Groups Links
(Continue reading)

giskier | 9 Aug 20:11 2009

Re: process the list in reverse order in batch file


I missed the closing quote:

%str:~0,5%

Good Luck

GISkier

Raagu wrote:
> 
> Hi I have tried this , But it didnt work
> I have tried simple example..
> 
> set str = zero.core
> 
> if /I "%str:~0,5" == "zero."  echo HI
> 
> It didnt print anything..
> 
> What is the problem here ??
> 
> 
> giskier wrote:
>> 
>> In your code to process each line you add the following (which will take
>> the first five letters of the variable and compare to zero. (including
>> period)).  As you can see, if the comparison matches it jumps over the
>> processing and returns without doing anything.
>> 
(Continue reading)

giskier | 10 Aug 05:57 2009

Re: process the list in reverse order in batch file


You can assign the parameter to a temporary variable and use the variable:

:compile
set HelpVar=%1
if /I "%HelpVar:~0,5%" == "zero."  ...etc...

GISkier

Raagu wrote:
> 
> ya it worked fine :)
>  But in my code o am gettring str as a pameter from other piece  of code..
> 
> Here is my snippet
> 
> :processEach
> for /F "tokens=1,* delims=," %%r in ("!revDepends!") do (set
> revDepends=%%s& call :compile %%r)
> if not "!revDepends!" == "%1" goto :processEach
> 
> :compile
> echo %1
> if /I "%(%1):~0,5%" == "zero."  echo HI 
> 
> How Do I put %1 (that conatns a single value , may be 'zero.core' ) in if
> condition...
> 
> 
> 
(Continue reading)

giskier | 11 Aug 06:24 2009

Re: process the list in reverse order in batch file


There are 2 ways to return from a call

1)  goto :EOF
2)  exit /B X

In way 2, X is a number, and the errorlevel variable will be set to X.

Example

for %p in (one two three) do call :showParam

:ShowParam
echo %1
goto :EOF

Good Luck

GISkier

Raagu wrote:
> 
> oh ok Thanks...
> 
> Now
> 
> I have a bat script which conatins a for loop
> 
> for  ******** do call :LABEL1
> 
(Continue reading)


Gmane