3

how to convert batch file from .tif to .bil format using gdal_translate in windows CMD command line, file in the directory.

Directory path : D:\GDAL-TEST
001_mean.tif
002_mean.tif
003_mean.tif
004_mean.tif
So on....

I have one code but by this code we can convert single file at a time but i want to loop through all raster which have .tif extension in the directory and convert it to .bil format. Please want a solution

My code. I a running this code on GDAL Command window on windows 7 platform.

gdal_translate -of "ENVI" D:\GDAL-TEST\001_mean.tif D:\GDAL-TEST\001_mean.bil
11

From the command line you can write

for %i in (*.tif) do gdal_translate -of "ENVI" %i %i.bil

The command above will convert all tif to bil in the actual directory. The output name will be some_name.tif.bil. From a batch (.bat) file you must use double percent sign for variables.

for %%i in (*.tif) do gdal_translate -of "ENVI" %%i %%i.bil

If you would like to remove .tif from the output file name you see the following https://stackoverflow.com/questions/3215501/batch-remove-file-extension

  • 1
    for %%i in (*.tif) do gdal_translate -of "ENVI" %%i %%~ni.bil should deliver the right filenames. Assuming that the batch is in the same folder as the tif files, and gdal_translate somewhere in the PATH variable. – AndreJ Aug 28 '16 at 8:36

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