user2439245
user2439245

Reputation: 37

batch file to run recursively

I would like to run command line utility recursively for all folders in windows. I have tried with the following, but not succesfully.

FOR /R "C:\AMDB\30-Apr-2013\Input\" %%G in (.) DO (

shp2sdo.exe %%~ni %%~ni -g geometry -d -x (-180,180) -y (-90,90) -s 8307 -t 0.5 -v

Pushd %%G
Echo now in %%G
Popd )
Echo "back home"

Upvotes: 0

Views: 254

Answers (3)

dbenham
dbenham

Reputation: 130819

The reason your code does not execute is because the ) characters in your SHP2SDO.EXE arguments are closing your FOR DO loop prematurely. Those parentheses need to be escaped:

FOR /R "C:\AMDB\30-Apr-2013\Input\" %%G in (.) DO (

  shp2sdo.exe %%~ni %%~ni -g geometry -d -x (-180,180^) -y (-90,90^) -s 8307 -t 0.5 -v

  Pushd %%G
  Echo now in %%G
  Popd
)
Echo "back home"

Upvotes: 0

Endoro
Endoro

Reputation: 37569

try this:

@echo off &setlocal
FOR /R /D "C:\AMDB\30-Apr-2013\Input" %%G in (*) DO (
    Pushd "%%G"
    shp2sdo.exe "%%~ni" "%%~ni" -g geometry -d -x (-180,180) -y (-90,90) -s 8307 -t 0.5 -v
    Echo now in %%G
    Popd 
)
Echo "back home"

Upvotes: 1

Magoo
Magoo

Reputation: 80013

We have no idea of what you mean by "successfully." We can conclude it's not doing what you expect, otherwise you'd not be asking the question.

Now - is the problem that it's not running your utility in "all folders"?

  • You are only asking it to run in "C:\AMDB\30-Apr-2013\Input\" and directories in that subtree.

Are you showing us just the part you believe is at fault?

  • Perhaps shp2sdo.exe %%~nG rather than shp2sdo.exe %%~ni would work better for you

Or is it not giving you what you expect when you ECHO now in %%G ?

  • Perhaps if you told us what you expect and what you're getting it may be easier to help.

Upvotes: 0

Related Questions