Discussion:
[gdal-dev] Gdal_translate batch processing
gnihalk
2021-04-29 12:35:47 UTC
Permalink
Hi you all. I have a huge MODIS dataset and I need to translate them to tiff
but each data is in a different sub-folder.
C:\Users\HP\Desktop\modis\5000000889913\5000000889913\88258783\MOD10A2.2016322095024.hdf
C:\Users\HP\Desktop\modis\5000000889913\5000000889913\96113659\MOD10A2.A2016321.h20v05.006.2016340133152.hdf
....
.....
the dataset sub-folders go like this...

and the code that im trying to run is:
for /R C:\Users\HP\Desktop\modis\5000000889913\5000000889913\88258783 %f IN
(MOD10A2.2016322095024.hdf) do gdal_translate.exe -sds -of gtiff %f
C:\Users\HP\Desktop\modis\5000000889913\5000000889913\88258783\MOD10A2.2016322095024.tiff

I tried to make a loop for all subfolders that I have but I got an error
massage. I would appreciate it if I can take your opinions about it. I am
also not sure that I post this question in true title/section.
Thank you,
Gulnihal




--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
M***@yukon.ca
2021-05-04 17:33:51 UTC
Permalink
Hi Gulnihal,

Something like this should work:

pushd C:\Users\HP\Desktop\modis
for /r %F in (*.hdf) do @echo gdal_translate -sds %F %~dpnF.tif
popd


This is a dry run to show what it will attempt, it won't actually do anything. Remove the "@echo" part to make it active. Double the % to use in a batch file (so "for /r %%F ...").

For help on what is being done here see:

* https://ss64.com/nt/for_r.html
* https://ss64.com/nt/syntax-args.html - what the "%~dpnF" part is doing.
* https://ss64.com/nt/syntax-percent.html


Cheers,

-Matt

-----Original Message-----
From: gdal-dev <gdal-dev-***@lists.osgeo.org> On Behalf Of gnihalk
Sent: April 29, 2021 5:36 AM
To: gdal-***@lists.osgeo.org
Subject: [gdal-dev] Gdal_translate batch processing

<strong>*** External email: Do not click on links or attachments except from trusted senders. *** ******************************************************************************************</strong>
<br>
<br>
Hi you all. I have a huge MODIS dataset and I need to translate them to tiff but each data is in a different sub-folder.
C:\Users\HP\Desktop\modis\5000000889913\5000000889913\88258783\MOD10A2.2016322095024.hdf
C:\Users\HP\Desktop\modis\5000000889913\5000000889913\96113659\MOD10A2.A2016321.h20v05.006.2016340133152.hdf
....
.....
the dataset sub-folders go like this...

and the code that im trying to run is:
for /R C:\Users\HP\Desktop\modis\5000000889913\5000000889913\88258783 %f IN
(MOD10A2.2016322095024.hdf) do gdal_translate.exe -sds -of gtiff %f C:\Users\HP\Desktop\modis\5000000889913\5000000889913\88258783\MOD10A2.2016322095024.tiff

I tried to make a loop for all subfolders that I have but I got an error massage. I would appreciate it if I can take your opinions about it. I am also not sure that I post this question in true title/section.
Thank you,
Gulnihal




--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
Loading...