5

I have a huge MODIS dataset and I need to translate them to tiff from hdf.

My input path is: C:\Users\HP\Desktop\deneme\ham_veri and hopefully, the output path is: C:\Users\HP\Desktop\deneme\yeni

This is what I'm trying to run for batch processing:

FORFILES /m MOD10A2.A2016321.h20v05.006.2016340133152.hdf C:\Users\HP\Desktop\deneme\ham_veri "cmd /c gdal_translate -sds -of HDF4_SDS:hdf:@file:01 C:\Users\HP\Desktop\deneme\yeni\MOD10A2.A2016321.h20v05.006.2016340133152.tif"

and this is what I got from command prompt:

ERROR 6: Too many command options '%C:\Users\HP\Desktop\deneme\yeni%\@MOD10A2.A2016321.h20v05.006.2016340133152.tiff'

Where am I doing wrong?

5
  • If you have one file, why do you use FORFILES? Just wondering. Apr 30 at 18:46
  • I have many .hdf files in sub-folders. But currently what I'm trying to do is to extract all the hdf files in one folder manually (because I don't know how to make it with python and don't want to make everything too complicated for a newbie) and then write a code to translate hdf files to tiff with batch processing. Isn't that the code I should use? Apr 30 at 18:56
  • I'm not an expert on gdal_translate. I guess you should use /s for forfiles command to get files in subfolders. This is not related to the error, tough. Apr 30 at 19:04
  • Thank you so much for your idea. I'm going to work on it. Btw I think we are in the same country. Aren't we allowed to speak our native language here? Apr 30 at 19:11
  • If you have QGIS you can run the gdal translate command in batch. The Run as a Batch Process button shows in the form that opens when you open the tool.
    – johns
    Apr 30 at 19:30
4

First of all, make sure forfile command returns the files you want to process.

The next command prints all HDF files' name in the folder:

forfiles /p C:\Users\HP\Desktop\deneme\ham_veri /m *.hdf /c "cmd /c echo @path

You may think of using this:

FORFILES /m *.hdf /P C:\Users\HP\Desktop\deneme\ham_veri /C "cmd /C gdal_translate -sds @file C:\Users\HP\Desktop\deneme\yeni\@fname.tif"

But unfortunately, @fname returns file name with double quotes like "file". So, the full output path would be like C:\Users\HP\Desktop\deneme\yeni\"file".tif and this path is incorrect because of double quotes.

Therefore, you need to get rid of them. I, finally, found a solution as follows:

FORFILES /m *.hdf /P C:\Users\HP\Desktop\deneme\ham_veri /C "cmd /Q /C for %I in (@fname) do gdal_translate -sds -of GTiff @file C:\Users\HP\Desktop\deneme\yeni\%~I.tif"
1
  • No error messages, it worked. Thank you for the brief information. Apr 30 at 22:09

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.