Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to reproject, move from tab to shp and rename all the .tab contained in a folder tree using ogr2ogr.

I'm working with Windows 7, QGIS 1.8 installed with advanced OsGeo4w and gdal 1.9.2. I have no experience in batch.

Here's the code :

for /R %%f IN ('D:\3.BATCH\FAUNE\*.tab') do C:\Users\Samy\Desktop\SIGMA\15.webmapping\ms4w\tools\gdal-ogr\ogr2ogr.exe -s_srs EPSG:3727 -t_srs EPSG:2975 %%f "ESRI Shapefile" %%f_2975.shp %%f

By calling this .bat into the cmd line, nothing append. When I simplify the code, I have in the best case "Unable to open" as Nik posted in the 3rd ressource below.

I wrote this code with the following questions:

  1. ogr2ogr convert all shapefiles in a directory

  2. Is there any way to reproject multiple layers in QGIS?

  3. How to reproject shapefile using ogr2ogr

According to resource 1, I translate the -f "MapInfo File" "" "%f" into %%f "ESRI Shapefile" %%f_2975.shp %%f because as it is shape, I can't use dpnf.

According to resource 2, I wrote -s_srs EPSG:3727 -t_srs EPSG:2975 to reproject.

Finally I checked that the "Hide extensions for known file types" was off, according to ressource 3.

I don't know what to do now. There seems to be so many different ways to write this one line of code.

share|improve this question
up vote 2 down vote accepted

There are a few %%f too much in your command line. This one worked for me (with another conversion target):

for /R %%F IN ('D:\3.BATCH\FAUNE\*.tab') do C:\Users\Samy\Desktop\SIGMA\15.webmapping\ms4w\tools\gdal-ogr\ogr2ogr.exe -s_srs EPSG:3727 -t_srs EPSG:2975 -f "ESRI Shapefile" %%~dpnF_2975.shp %%F

Main obstacle is that %%F already contains the file extension, so you have to skip that with ~dpnF_2975.shp.

Note that f and F are considered as different by the Operating System.

You skipped the ~dpnf, but that is the essential part of clipping the file name to the desired part without extension. You can replace dp with full drive and path name.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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