Windows %CD% variable with "&" in foldername in batch file

0

I noticed that the variable %cd% and most of it's variants doesn't support "&" characters as a result only haf of the patch will be visible. An example:

echo %CD%

gives:

D:\Documents\1# Data\School 

While it should show:

D:\Documents\1# Data\School & Werk\Leerstad

I was wondering if their is some way to bypass this?

Jens Ingels

Posted 2019-02-28T14:53:11.550

Reputation: 101

3Try ECHO "%CD%"; that will return the pathname quoted - which you will need to do in Batch anyway, because the pathname has spaces in it. – Jeff Zeitlin – 2019-02-28T14:57:46.650

Thx, wasn't aware this was supported in batch – Jens Ingels – 2019-02-28T15:11:47.287

2I like Postel's Law -- "Be conservative in what you do, be liberal in what you accept from others." Coding to handle items with spaces or special characters is a good way to "be liberal". But as you are seeing, it's not always straightforward. Thus, a lot of poor code will fail when it meets such paths. So I strive to "be conservative" by avoiding spaces or (most) special characters in paths. You can control the batch files that you write, but you never know when some code outside of your control will have trouble with such a path. I would use D:\Documents\1-Data\SchoolAndWerk\Leerstad. – Doug Deden – 2019-02-28T15:46:15.577

No answers