# How to process files in a series based on the date of the filename(Batch)



## _unknown_ (Oct 28, 2014)

How will merge/process the files in a series based on their date using the script below? Whenever the system is down and you weren't able to process the files let's say for one week, it will just check for the last date where it stop and process it and then process the next date and process the next and so on. But how can I do that? Any idea?

File names:


T2010232034000.L2_LAC.Tera.tif
 T2010232035000.L2_LAC.Tera.tif
 T2010232036000.L2_LAC.Tera.tif
 T2010232037000.L2_LAC.Tera.tif


 T2010233045000.L2_LAC.Tera.tif
 T2010233046000.L2_LAC.Tera.tif
 T2010233047000.L2_LAC.Tera.tif
 T2010233048000.L2_LAC.Tera.tif
 T2010233049000.L2_LAC.Tera.tif
Note: T2010232034000 = Terra/Data Year/Julian Date/HH/MM/SS


```
@echo on
setlocal EnableDelayedExpansion

rem Modify following variables
set "in_path=E:\Proc\Pro\"
set "out_path=E:\Proc\Mer"
set "proc_path=E:\Proc\Proc_Pro"

rem DON'T modify the following variables
set "yearDay="
set "fileList="
set "numFiles=0"

md %out_path%
md %proc_path%

rem Process all *.tif files in input path
pushd "%in_path%"
for %%a in (*.tif) do (
   set "fileName=%%a"
   rem If the YearDay in this file is the same of previous one
   if "!fileName:~1,7!" equ "!yearDay!" (
      rem Join this filename to previous list
      set "fileList=!fileList!!fileName! "
      set /A numFiles+=1
   ) else (
      rem Merge the files in the list if there are more than 2, in the out_path leaving only TYYYYDDD.L2_LAC.Tera.tif
      if !numFiles! gtr 2 (
         gdal_merge.py -n 0 -a_nodata -32767 -of GTiff -o %out_path%\T!yearDay!.L2_LAC.Tera.tif !fileList!
         rem Move processed files to a different directory
         for %%a in (!fileList!) do move %%a "%proc_path%"  >nul
      )
      rem And start a new YearDay and fileList
      set "yearDay=!fileName:~1,7!"
      set "fileList=!fileName! "
      set numFiles=1
   )
)
rem Merge the files in the last list if there are more than 2
if !numFiles! gtr 2 (
   gdal_merge.py -n 0 -a_nodata -32767 -of GTiff -o %out_path%\T!yearDay!.L2_LAC.Tera.tif !fileList!
   for %%a in (!fileList!) do move %%a "%proc_path%"  >nul
)
popd
```


----------



## valis (Sep 24, 2004)

closing duplicate, please respond at http://forums.techguy.org/dos-other/1138488-dos-batch-how-process-files.html.


----------

