Navigate to folder: The DATE environment variable cannot be used

Here you can propose new features, make suggestions etc.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Mapaler
Junior Member
Junior Member
Posts: 17
Joined: 2022-01-29, 06:05 UTC

Navigate to folder: The DATE environment variable cannot be used

Post 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.
User avatar
nsp
Power Member
Power Member
Posts: 1944
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: The DATE environment variable cannot be used

Post 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%"
User avatar
Dalai
Power Member
Power Member
Posts: 10019
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

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

Post 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
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
NotNull
Senior Member
Senior Member
Posts: 298
Joined: 2019-11-25, 20:43 UTC
Location: NL

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

Post 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
Mapaler
Junior Member
Junior Member
Posts: 17
Joined: 2022-01-29, 06:05 UTC

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

Post by *Mapaler »

I understand and thank youes.
Post Reply