Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

cd will not work with any folder name which includes the &

Mar 29, 2015 3:20AM PDT

Hi If I attempt to cd to any path which includes a directory name using the & symbol then it fails. For example if I try to cd to a directory named test&go I would receive the following message
The system cannot find the path specified, 'go' is not recognised as an internal or external command, operable program or batch file.

Any assistance would be greatfully received.

o/s windows 7 64 bit

Discussion is locked

- Collapse -
Sounds right.
Mar 29, 2015 3:37AM PDT
- Collapse -
Quotes worked for me.
Mar 29, 2015 3:46AM PDT

CMD prompt here.
"
C:\Users\proffitt\Desktop>cd test&go
The system cannot find the path specified.
'go' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\proffitt\Desktop>cd "test&go"

C:\Users\proffitt\Desktop\test&go>
"

- Collapse -
Re: ampersand
Mar 29, 2015 4:05AM PDT
- Collapse -
cd will not change to any directory named with a &
Mar 29, 2015 4:28AM PDT

Hello Kees
Thanks for info. Is it not the case that & is a legitimate character for naming a file or folder?

- Collapse -
Sure.
Mar 29, 2015 4:38AM PDT

But it's used as a command separator in a command for cmd also. And that has precedence. That's not a bug.

The 4 alternatives
- cd test & cd go
- cd "test&go"
- cd test^&go
- split into 2 lines: cd test and cd go
Choose the one you like most to use.

Kees

- Collapse -
cd will not change to any directory named with a &
Mar 29, 2015 5:01AM PDT

Hi Kees. If & had been declared as an invalid character for naming files and folders there would not be an issue. In my case test&go is just a string not an attempt to use multipe commands - cd "test&go" works just fine. I am going to have to brush up my dos commands!! Again thanks for your help.

- Collapse -
Naming conventions
Mar 29, 2015 5:26AM PDT

In that case the parentheses ( and ) should have been disallowed also. But the filename rules for NTFS have been defined before the full syntax of CMD was designed. And it would have been impossible to forbid using them then.

All details about the rules for filenames are documented in https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#naming_conventions.

All reserved characters had a meaning mentioned there (except possibly the quote used around filenames with a space in a command) already were used in the MS-DOS command interpreter. So adding new ones (like the parentheses and the ampersand in a new version of the language) resulted in this (easy to solve) conflict.

Also note this nice little sentence: "The shell and the file system have different requirements. It is possible to create a path with the Windows API that the shell user interface is not able to interpret properly."

Kees

- Collapse -
cd will not change to any directory named with a & by confu
Mar 29, 2015 8:12PM PDT

Hi Kees many thanks for your comprehensive reply esp your last sentence. One lives and learns!!!

- Collapse -
cd will not change to any directory named with a &
Mar 29, 2015 4:14AM PDT

Many thanks for your speedy reply bob. This query really resulted from my problems installing the android SDK manager. This ultimately led to me examining a particular batch file called android.bat. Part of this batch file refers to executables whose paths include a directory with an & in it. The easiest way on the face of it would be change the name of the directory but the directory in question is user profile! I have found a reference how to do this but I am always reluctant to step into regedit. It looks as if I may have no choice. Anyway again many thanks for you help

- Collapse -
You could report that as a bug/needed enhancement.
Mar 29, 2015 4:28AM PDT

Since it's a batch file, why not add the escape \ or quotes?
Bob

- Collapse -
cd will not change to any directory named with a &
Mar 29, 2015 4:46AM PDT

Hi Bob I will have to have a think about what you and other correspondents have told me. I fear I'm not really clear what the android bat file is doing and until I do I will be wasting everyones time in pursuing this issue further. This is the first time I have ever used a forum and I am thankful for all the help received. Bye for now.

- Collapse -
By now you know it's a legitimate character in names.
Mar 29, 2015 4:50AM PDT

But for the command processor it has a special meaning and when we put spaces or other than a-z, 0-9 in names we have to be aware of the command processor.

Bob

- Collapse -
the folder that holds it
Mar 29, 2015 8:11PM PDT

should show the short DOS name that can be used for it?

- Collapse -
DIR and DIRCMD (the variable.)
Mar 30, 2015 1:07AM PDT

DIRCMD would change the display of DIR but I never found it to change what a batch file would have to process.
Bob