2

Consider the following commands given from a cmd prompt:

D:\test>cd D:/

D:\>cd /test

D:\test>pushd D:/
The syntax of the command is incorrect.

D:\test>pushd "D:/"

D:\>popd

D:\test>cd ..

D:\>pushd /test
The syntax of the command is incorrect.

D:\>pushd "/test"
The syntax of the command is incorrect.

D:\>pushd "D:/test"

D:\test>

It seems that cd process correctly slashes / in general, while pushd only accepts them only if at the same time:

  • The argument is quoted
  • The full path is given

Does this correspond to truth? Is it documented anywhere?

Antonio
  • 427

1 Answers1

3

Read MSDN article Naming Files, Paths, and Namespaces:

Naming Conventions The following fundamental rules enable applications to create and process valid names for files and directories, regardless of the file system:

  • Use a period to separate the base file name from the extension in the name of a directory or file.
  • Use a backslash (\) to separate the components of a path. The backslash divides the file name from the path to it, and one directory name from another directory name in a path. You cannot use a backslash in the name for the actual file or directory because it is a reserved character that separates the names into components.
  • Use a backslash as required as part of volume names, for example, the "C:\" in "C:\path\file" or the "\\server\share" in "\\server\share\path\file" for Universal Naming Convention (UNC) names. For more information about UNC names, see the Maximum Path Length Limitation section.

More reading on (\)/ (reverse) solidus: Why does Windows use backslashes for paths and Unix forward slashes?

In the command interpreter (cmd.exe), you can use / as a separator of path components in many cases, but not always. Example:

==> d:\bat\so\second.bat a b c
second.bat parameters: %*=a b c

==> d:/bat/so/second.bat a b c
second.bat parameters: %*=a b c

==> type d:/bat/so/second.bat
The syntax of the command is incorrect.

==> type "d:/bat/so/second.bat"
The system cannot find the file specified.

==> type d:/bat/so\second.bat
The syntax of the command is incorrect.

==> type "d:/bat/so\second.bat"
@echo %~nx0 parameters: %%*=%*

==>

Another example:

==> dir d:/bat/so/second.bat
Parameter format not correct - "bat".

==> dir "d:/bat/so/second.bat"
 Volume in drive D is DataDisk
 Volume Serial Number is 4288-6B27

 Directory of d:\bat\so

File Not Found

==> dir "d:/bat/so\second.bat"
 Volume in drive D is DataDisk
 Volume Serial Number is 4288-6B27

 Directory of d:\bat\so

27.11.2015  17:35                32 second.bat
               1 File(s)             32 bytes
               0 Dir(s)  910 153 654 272 bytes free

==>
JosefZ
  • 13,855