Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
793 views
in Technique[技术] by (71.8m points)

windows - What is the difference between and \ in file path

What is the difference between single slash and double slash in file path for Windows operating system such as

c:\PersonalMyFolder\MyFile.jpg

and

c:PersonalMyFolderMyFile.jpg

What if I use the single or double slash because I have tried both for storing images in my code (in webconfig file) and both of them work fine.

Is there any difference??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Windows ignores double backslashes. So while the second syntax with is correct and you should use that one, the first with \ works too.

The only exception is double-backslash at the very beginning of a path that indicates a UNC path.
See Universal Naming Convention.


Though note that in many programming languages like C, C++, Java, C#, Python, PHP, Perl, a backslash works as an escape character in string literals. As such, it needs to be escaped itself (usually with another backslash). So in these languages, you usually need to use a double backslash in the string literal to actually get a single backslash for a path. So for example in C#, the following string literal is actually interpreted as C:PersonalMyFolderMyFile.jpg:

var path = "C:\Personal\MyFolder\MyFile.jpg";

Though there are alternative syntaxes. For example in C#, you can use the following syntax with the same result:

var path = @"C:PersonalMyFolderMyFile.jpg";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...