2

How am I going to automatically check all the files that were added to the directory and then warp it immediately?Because everyday I am downloading hdf files and warping it from time to time is a waste of time. That's why I need it in batch process and automatic.

Thank you in advance!

script:

set in_path=path_to_input
set out_path=path_to_output

md %out_path%
cd /d %in_path%

FORFILES /m *A1_AC*.hdf /C "cmd /c gdalwarp -geoloc -t_srs EPSG:4326 -te 113.205 1.120 157.105 2.005 HDF4_SDS:hdf:@file:01 %out_path%\@fname.tif"*
lovelyvm
  • 160

1 Answers1

0

you can sort directory content by creation (/tc) date (/-od) (descending, newest first)

dir /o-d /tc

then parse the first (date) and/or second (time) field and compare with the current date (%date%) and time (%time%) with if comparison operator:

for /f "tokens=1,2,5" %a in ('dir /-b /o-d /tc') do @if %a==%date:~4% (if %b==%time:~0,5% (echo %c))

selects first (date), second (time), and fifth (filename) fields, if condition is true outputs the last one (%c)


notes

  • prepending an extra % to local for variables is required if the code is put in a script (.bat file)
  • time (short time on intl.cpl) in the machine should be in H:mm tt (H=24) format, as dir's output depend on it
  • :~ in %date% and %time% inside the code is string manipulation (substring) operator to make their value comply with the date and time format in dir's output
  • scheduled task for checking for events on temporal basis, and running the code/script accordingly can be created with schtasks external command (%windir%\system32\schtasks.exe)