0

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?

Thanks

alvaropr
  • 699
  • 9
  • 20
  • 2
    `%date%` however in most countries the date separator is illegal for filenames. So use something like this `%date:/=-%`. See `set /?` for help. For a full list of variables see this program here that you can make. https://winsourcecode.blogspot.com/2019/05/listenvironmentexe-list-system-user.html. General CMD Cheat Sheet https://winsourcecode.blogspot.com/2019/12/command-prompt-cheat-sheet.html –  May 04 '20 at 07:11
  • Take a look at this thread: [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 May 04 '20 at 08:58
  • Thanks. I have updated my Initial questions because I managed to get the date in proper format but could not introduce it in a path. – alvaropr May 14 '20 at 06:58

1 Answers1

0

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.

alvaropr
  • 699
  • 9
  • 20