-1

When I try CD\ from Our Map Drive I get:

error :'cd\' is not recognized as an internal or external command, operable program or batch file.

But with space (cd \) it s working ,

T:\bat>cd\

'cd\' is not recognized as an internal or external command, operable program or batch file.

T:\bat>cd \

T:\>

Could anyone tell me why this is?

  • 1
    Works fine without the space on a mapped network share on Windows 7. What exactly is the problem? – harrymc Jun 8 '14 at 12:12
  • 2
    cmd.exe is not the same as MS-DOS – Kevin Panko Jun 8 '14 at 16:09
2

CmdPi's answer repeats the received wisdom that Microsoft's command interpreters work like UNIX shells. This is the way that everyone voted with their feet in the 1980s. But in fact they didn't and still don't.

Command names could and can be separated from command tails by a fair number of characters, not solely by whitespace. One can use the equals character, for example, or the comma. path=C:\DOS is a command and a tail. So too is dir,dos. Most famously, one can use the full stop. Hence the well-known echo. trick for echoing a blank line in a command script. What is less well known is that echo;, echo+, echo=, echo(, echo,, echo[, echo], echo\, and echo/ will all do the same (albeit not always for some of them).

In fact, there's a DOS API call (int 21h,ax=6505h) that can be used to obtain the complete list of characters that are so-called "filename termination characters". And DOS command interpreters use it to determine what characters terminate a command name and begin the command tail. (Microsoft command interpreters for non-DOS operating systems probably just hardwire the set of characters.)

The backslash is one of those characters, and in command interpreters from Microsoft's command in MS-DOS to Microsoft's cmd in Windows NT (including IBM's/Microsoft's cmd for OS/2 along the way) one can execute cd\ and the result will be that the command interpreter changes directory to \. Whether the termination character is included in the command tail actually varies from command to command. With the cd command it is. With the dir and path commands it is not. (Yes, the command-line parser in Microsoft command interpreters behaves differently according to what built-in command is to be run.)

This has never really been documented, though. As I said: most people voted with their feet in the 1980s to embrace the UNIX shell paradigm, even though things like argument parsing and quoting are a vast conspiratorial fiction implemented not by the command interpreter at all but by the runtime libraries of several programming language implementations for DOS; and you'll find that most of the literature states with confidence that whitespace separates name from tail, even though it isn't actually true. echo. is usually described a quirk and a trick, and very rarely described as simply one case of an overall syntax that Microsoft's command interpreters have employed for roughly three decades.

I recommend following the 1980s trend here, and not relying upon this little-known syntax. Use whitespace. It's what people document. It's what the likes of IBM and Microsoft themselves document. It's what folk wisdom states to be the case. It's what the UNIX-heads expect. ☺

My command interpreter went with the syntax charts and descriptions that are in the IBM doco. However, you'll find that FreeCOM implements this little-documented behaviour, as do JP Software's command interpreters and the command from OpenDOS. JP Software's doco recommends using space and describes using other termination characters as "illegal". It is, however, one of the few places that actually states in official documentation that there's an alternative to be had.

Further reading

  • 2
    Nice answer, but to the wrong question. This has nothing to do with this question. – harrymc Jun 8 '14 at 12:14
1

CD is a command, \ a parameter.

You have to separate both with a space.

  • 2
    That isn't strictly true. At least in windows 7 and beyond you do not need to separate them. At some point prior you did, but I can't remember which version of windows implemented the change. – EBGreen Mar 31 '14 at 15:10
  • its working in different Drive Microsoft Windows XP [Version 6.1.7601] (C) Copyright 1985-2001 Microsoft Corp. U:\bat>cd\ U:\> – user311952 Mar 31 '14 at 15:10
  • Having said that, it is not particularly onerous to simply use the space at all times to maintain backwards compatibility. – EBGreen Mar 31 '14 at 15:11
  • also tested in Win XP ,7 and 8 – user311952 Mar 31 '14 at 15:14
  • My only guess (and this is pure guess) is that it has to do with the mapping of the drive. The command prompt has never liked unc paths at all and I suspect that even though the drive is mapped it still treats it as a different (read reduced capability) drive system. – EBGreen Mar 31 '14 at 15:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.