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
==>
/?
directory usingcd /?
can give you some help with thecd
commandD
by doingcd /D
as that is a validcd
option.cmd
shell in Microsoft's Windows, therefore you have to put the slash the wrong way around. (This is because of a historical accident, there the slash was used to give options. It seemed like a good idea at the time, as Microsoft had not heard of directories at this time, (or of windowing systems, or networks))./
was used (without a valid option). My use case concerns paths generated bycmake
to be used in a configure file generating a batch script.