3

I'm just curious about this:

It's possible to create a Folder, in Windows Explorer, with the same Name as an Environment Variable (like %ProgramData%).

The same procedure in CMD.exe with mkdir prevents this and if i try to access this folder, i always get re-directed to the Environment Variable.

But is there any known way to access this kind of Folder with the command-line?

Are there any escape parameters for this, to prevent resolving the variable?

1

2 Answers 2

1

For accessing the directory (via cd), you could use the console's character replacement (aka wildcards), and replace one of (or both) the percent signs with a question mark. e.g.:

  • cd ?ProgramData%
  • cd %ProgramData?
  • cd ?ProgramData?

Alternatively, and for use with other commands like rename, md and such, you can escape the percentage with a caret (^). e.g:

  • md ^%ProgramData^%
3
  • This works, so far. But for mkdir and rename, this is no solution. :/ Sep 8, 2016 at 13:50
  • I assumed that when you asked about "Accessing" the folder, that you meant you wanted to navigate into the folder. Sep 8, 2016 at 13:53
  • No problem; it was an interesting question. :) Sep 8, 2016 at 14:00
0

I was able to mkdir with

mkdir "%test%"

and then navigate to it with

cd "%test%"

Also works with rename

3
  • 1
    Is %test% a resolvable Environment Variable on your System? Sep 8, 2016 at 13:56
  • oh, good question. I'll set it and try that again. Sep 8, 2016 at 13:57
  • 1
    Interesting. test is equal to value. When I mkdir "%test%" I get a directory named value. Should have seen that coming. hehe Sep 8, 2016 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .