Windows Task Scheduler specify date to dynamically create log dirs

3.3k Views Asked by At

I have some R scripts that I would like to run automatically on Windows. Using the package taskscheduleR I can, directly from R, set up all these tasks on Windows Task Scheduler.

They create with the following action within the task properties:

/c path/to/Rscript.exe "path/to&/my_script.R" >> "path/to/static/my_log.log" 2>&1

While I understand the syntaxis I would like to know if there is a way to pass the current date to the "path/to/static/my_log.log" in the format AAAA-MM-DD.

Is there anything similar in Windows to a environment variable but that used for dates?

Some string like "path/to/dinamic/%%SYS.DATE%%/my_log.log" that I can send in the task creation to dinamically create dirs every date the tasks are run?

1

There are 1 best solutions below

0
alvaropr On

If %date% comes in the wrong format (as in my computer comes in DD/MM/AAAA) in order to formatt the date in one-liner to be included in the path I can use:

echo /foo/dirpath/with/embedded/date/for/%date:~6%-%date:~3,2%-%date:~0,2%/example

Output

foo/dirpath/with/embedded/date/for/2020-05-14/example

Thanks @Mark for the comment that lead to the solution.