1

We have hundreds of dgn files which have to be converted to shapefiles. I am trying to use these commands to batch convert all the dgn files in a folder.

for %%f in (*.dgn) do ogr2ogr -f "ESRI Shapefile" ".\point\%~nf.shp" "%%f" -where "OGR_GEOMETRY = 'POINT'" -skipfailures
for %%f in (*.dgn) do ogr2ogr -f "ESRI Shapefile" ".\linestring\%~nf.shp" "%%f" -where "OGR_GEOMETRY = 'LINESTRING'" -skipfailures
for %%f in (*.dgn) do ogr2ogr -f "ESRI Shapefile" ".\polygon\%~nf.shp" "%%f" -where "OGR_GEOMETRY = 'POLYGON'" -skipfailures

But I am getting an error of

"|f" is not recognized as an internal or external command, operable program or batch file

Could anyone tell me what the problem with this command is?

Update: The problem is with the bat file format. It has to be saved in ANSI & not in other format's. The code given by Zoltan in the answer works perfectly

https://stackoverflow.com/questions/27205097/ansi-unicode-conflict-in-batch-file

3

If you run it from a batch (.bat) file you have to use double percent marks for '~nf' too:

for %%f in (*.dgn) do ogr2ogr -f "ESRI Shapefile" ".\point\%%~nf.shp" "%%f" -where "OGR_GEOMETRY = 'POINT'" -skipfailures

  • Still getting the same error. "'■f' is not recognized as an internal or external command, operable program or batch file." – joseph_k Dec 14 '15 at 2:31
  • Try this: for %%f in (*.dgn) do echo "%%~nf.shp". It works for me. Did you test your ogr2ogr command? – Zoltan Dec 14 '15 at 6:50
  • Still the same. "'■f' is not recognized as an internal or external command, operable program or batch file." – joseph_k Dec 14 '15 at 13:09
  • You have to use double "%%" in a bat file, if you type in your command at the command prompt use single "%", e.g. type in: for %f in (*.dgn) do echo "%~nf.shp" – Zoltan Dec 14 '15 at 14:06
  • It's working if i run it through command prompt (single "%"). But if i run the same using bat file (Double %%), again getting the same error. – joseph_k Dec 15 '15 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.