0

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!

MichaelS
  • 5,941
  • 6
  • 31
  • 46
peroman200
  • 13
  • 5
  • 2
    Change the backticks around the `dir` command to single-quotes `'` as documented. Add a `pause` instruction on the next line to hold the window open, or preferably run from the command prompt, don't click a batch. – Magoo Jul 04 '17 at 15:24

1 Answers1

1

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.

Stephan
  • 53,940
  • 10
  • 58
  • 91