1

I want to use cURL to automatically download files. Tho, the files have the current date in their name and I would like to know how to automate the name to the current date if that makes sense! :) Ex.:

@echo [off]
cd F:\Documents
f:
cURL https://dd.weather.gc.ca/model_hrdps/east/grib2/18/001/CMC_hrdps_east_TMP_TGL_120_ps2.5km_2020110418_P001-00.grib2 -o "HRDPS 18z TMP_TGL_120 f001.grib2"
pause

The 2020110418 in the file name would be today's date and I would like it to be automated

It is my first project with batch files. Hope it is clear and thanks for the help! :)

TechEdd_YT
  • 95
  • 5
  • Have you searched this site? [How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?](https://stackoverflow.com/q/203090) – aschipfl Nov 05 '20 at 02:41

1 Answers1

0

Now every modern windows machine has Powershell, so using Powershell with batch to get the date parts split (regarding regional settings):

for /f "tokens=1,2,3 delims=_" %%i in ('powerShell -c "& {Get-Date -format "MM_dd_yyyy"}"') do (
    set MM=%%i
    set dd=%%j
    set yyyy=%%k
)
echo %yyyy%%mm%%dd%

Please tell what is 18, so it could be added like this


@Stephan nice, didn't thought this way:

for /f "tokens=* delims=" %%i in ('powerShell -c "& {Get-Date -format "yyyyMMdd"}"') do echo %%i
Wasif
  • 14,755
  • 3
  • 14
  • 34
  • thank you! :) But how can we copy the echo to the url? 18 is just the hour at which the weather model ran. – TechEdd_YT Nov 05 '20 at 19:06
  • Ok I solved it! I juste need to add the `%yyyy%%mm%%dd%` to the URL. Like this: `cURL https://dd.weather.gc.ca/model_hrdps/east/grib2/12/001/CMC_hrdps_east_TMP_TGL_2_ps2.5km_%yyyy%%mm%%dd%12_P001-00.grib2 -o HRDPS.12z.TMP_TGL_2.f001.grib2 ` – TechEdd_YT Nov 07 '20 at 01:34