What is a minimal valid UNC path?

2019-08-05 08:54发布

问题:

I want to make a library that (among other things) parses UNC paths, but I don't fully understand the grammar.

Common example is: \\server\share\path

Are all of those required for a valid file path? I can navigate to \\server (without share) using Windows Explorer, but I assume it is using some share discovery protocol, not something filesystem APIs understand — is this right?

回答1:

You are correct. A UNC path is required to have share name component.

Quoting MSDN:

UNC = \\<hostname>\<sharename>[\<objectname>]*

The <hostname>, <sharename>, and <objectname> are referred to as "pathname components" or "path components". A valid UNC path consists of two or more path components.

https://msdn.microsoft.com/en-us/library/gg465305.aspx