Could you please correct my batch command?

I had 100 img images which need to be converted into 8 unsigned bit format for further use in TIMESAT.

mkdir test for %%f in (*.img) do gdal_translate -of ENVI -scale -1 1 1 255 -a_nodata 0 -co INTERLEAVE=BSQ "%%f" test/%%f.dat

  • 1
    Would you be able to edit your question to say what happens when you run your code, please? Our volunteers are usually happy to try and help with code when people show what they have tried and precisely where they are stuck but not to be used as a code writing/debugging service.
    – PolyGeo
    Commented Feb 17, 2015 at 9:04
  • What happens when you run your command on a single .img file?
    – til_b
    Commented Feb 17, 2015 at 9:08
  • When I run that command on a image, it does what you'd expect it to do. The output naming scheme is a bit unfortunate, as you'll end up with files that are named .img.dat which is somewhat confusing, but apart from that it appears to be working. Commented Feb 17, 2015 at 9:17
  • The result is still 32 bit floating file format. I'm expected to have an unsigned 8 bit file.
    – Magon
    Commented Feb 17, 2015 at 9:23
  • There is an edit button beneath your question that will enable you to update it with that information. Think of comments as being temporary - they may or may not be read by potential answerers.
    – PolyGeo
    Commented Feb 17, 2015 at 9:48

2 Answers 2


You're expecting a 8-bit file, but you aren't exactly telling gdal that you want that. You need to add '-ot Byte'. See this help page for more info.

Your command becomes:

for %%f in (*.img) do gdal_translate -ot Byte -of ENVI -scale -1 1 1 255 -a_nodata 0 -co INTERLEAVE=BSQ "%%f" test/%%f.dat

If you want another file extension, you have to tweak the variable like this way:

for %%N in (D:\Karten\gdal\gdal2tiles\NL25\*.tif) DO gdal_translate -of vrt -expand rgba %%N D:\Karten\gdal\gdal2tiles\NL25\%%~nN.vrt

See http://ss64.com/nt/syntax-args.html for details on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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