Get directories of remote Server [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-13 03:08:51

问题


I'm trying to get all directories of a remote server.

For example: path: "\\Servename\folder" - it works!

path: "\\Servename" - error

I tried this:

DirectoryInfo dir = new DirectoryInfo (@"\\SERVERNAME"); <- Error happens here
//Get Directories from \\SERVERNAME
DirectoryInfo[] dirInfos = dir.GetDirectories();

Error: ERROR: The UNC path should be of the form \\server\share


回答1:


The reason is that you need to read available shares and not just the directories, as the comments answered.

However getting the list of all available shares on a server is a bit more complicated, it was already answered in a different question: Get a list of all UNC shared folders on a local network server

The most voted answer was Network Shares and UNC paths



来源:https://stackoverflow.com/questions/21938835/get-directories-of-remote-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!