I'm running small shell commands via tasks in VS code.
Within these commands I need the current timestamp.
Given I'm trying to run something like mkdir ./%date in a task:
{
"label": "make timestamp dir",
"type": "shell",
"command": "mkdir ${workspaceFolder}/%date%",
},
I tried using %date% and %time% but both is not substituted.
Alternatively I did see that VS code allows to call commands with ${command:CommandID}.
Therefore I installed a extension that generates a timestamp: https://marketplace.visualstudio.com/items?itemName=jsynowiec.vscode-insertdatestring
I tried to use that with ${command:insertDateString.insertTimestamp}:
{
"label": "make timestamp dir",
"type": "shell",
"command": "mkdir ${workspaceFolder}/${command:insertDateString.insertTimestamp}",
},
But that also is not substituted.
I'm out of ideas. How to add a timestamp in a VS code task?
You could try:
"command": "mkdir -p ${workspaceFolder}/`date +%Y%m%d-%H%M`",
That bash command date works for me. I assume you are using a unix-type shell and that'll work. -p forces it to create the new folder if it doesn't already exist.
See also in vscode how can I quickly generate a new file with datetime in the name?
[I don't know that you want ${workspaceFolder} -that appears to be a full path, maybe you want ${workspaceFolderBasename} but that is a separate issue.]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With