Iterating grib tools over a folder of grib files

159 Views Asked by At

I am attempting to mass-convert a large number of GRIB files to netCDF using grib tools (I am on Windows 7) in a batch file.

I am using this code:

for /f %%f in (`dir /b O:\Praksa\incadata\2014\01\01`) 
   do 
     echo %%f grib_to_netcdf -D NC_FLOAT -o *.nc *.grb

But when I run it nothing seems to happen except for CMD opening and closing really fast.

There is probably some syntax error I missed in there, but my main question is: Can I use wildcards (*) in grib tools statements? Also, are spaces in directory pathnames problematic?

Thanks!

1

There are 1 best solutions below

0
On

You got the syntax wrong. cmd is very picky about syntax. Try this:

@echo off
for /f %%A in ('dir /b /a-d z:\*') do (
     echo %%~fA grib_to_netcdf -D NC_FLOAT -o %%~dpnA.nc %%~dpnA.grb
)

%%~fA gives you the full qualified filename, %~dpnA the Drive, Path and Name only. See for /? for those modifiers. dir /a-d excludes foldernames. See dir /? for more info.