windowsbatch-filecmdogr2ogr

Batch script vs command line


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.


Solution

  • 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