2

When I run following command in cmd prompt it works:

for /R %f in (*.shp) do ogr2ogr -nln merge -update -append merge.shp %f 

but when I run it from .bat file it does not work. Saying -nln was unexpected.

Is there anyway I could run this from .bat file.

kinkajou
  • 3,664
  • 25
  • 75
  • 128

1 Answers1

3

The % character has a special meaning for command line parameters and FOR parameters.

To treat a percent as a regular character, double it: %%

When you execute it from a batch file, you should write it like this :

@echo on
for /R %%f in (*.shp) do ogr2ogr -nln merge -update -append merge.shp %%f 
pause

See this for more info : http://ss64.com/nt/syntax-esc.html

Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • 1
    is there any guide I can follow for batch scripting? – kinkajou May 08 '16 at 02:59
  • @kinkajou i edit my answer, so, take a look at the link above ;) – Hackoo May 08 '16 at 03:01
  • 2
    Type `Help` in a command prompt. Then either `command /?` or `help command`. The thing causing you grief is in `for /?`. Here's a cheat guide to punctuation in the command prompt http://stackoverflow.com/questions/31820569/trouble-with-renaming-folders-and-sub-folders-using-batch. –  May 08 '16 at 03:49
  • 2
    Doubling the `%` signs for batch files one of the first things mentioned when typing `for /?` in command prompt... – aschipfl May 08 '16 at 21:01