Page 1 of 1

Navigate to folder: The DATE environment variable cannot be used

Posted: 2022-01-29, 06:14 UTC
by Mapaler
I use ShareX screenshot software. It saves the screenshots to a folder of YYYY-MM(2022-01).
Image: https://i.imgur.com/YSlwoMp.png
I want to quickly navigate to the current folder.
The code should be

Code: Select all

CD %$Documents%\ShareX\Screenshots\%DATE:~0,4%-%DATE:~5,2%
Image: https://i.imgur.com/MFsGZgm.png
But I found that I couldn't use the DATE environment variable.

Re: The DATE environment variable cannot be used

Posted: 2022-01-29, 08:04 UTC
by nsp
What is not interpreted is the environment variable special expansions using "~" it is just valid under command interpreter.

As a workaround, You can create a button or even in hot-list command :

Code: Select all

cmd /c %COMMANDER_EXE% /O /S  "%$Documents%\ShareX\Screenshots\%DATE:~0,4%-%DATE:~5,2%"

Re: Navigate to folder: The DATE environment variable cannot be used

Posted: 2022-01-29, 11:35 UTC
by Dalai
The variables %DATE%, %TIME%, %CD%, %ERRORLEVEL% and some others are dynamically expanded by CMD. They are not regular environment variables! See also SS64 page: https://ss64.com/nt/syntax-variables.html

That means that you need to use CMD as part of your command, like the one shown by nsp.

Regards
Dalai

Re: Navigate to folder: The DATE environment variable cannot be used

Posted: 2022-01-29, 17:52 UTC
by NotNull
Or, another way of looking at it:

The CD command is not handled by CMD, but by TC, without calling CMD. And TC did not implement support for %DATE:~0,4%, etc.

Try this:
DIR /? & pause
vs.
CD /? & pause

Re: Navigate to folder: The DATE environment variable cannot be used

Posted: 2022-01-30, 07:20 UTC
by Mapaler
I understand and thank youes.