views:

244

answers:

4

Is there an api in windows that retrieves the server name from a UNC path ? (\\server\share)
Or do i need to make my own ?
I found PathStripToRoot but it doesn't do the trick.

A: 

I don't know if there is a specific API for this, I would just implement the simple string handling on my own (skip past "\\" or return null, look for next \ or end of string and return that substring) possibly calling PathIsUNC() first

Anders
that's what i did for now, but was checking if there was one in case there are some exceptions
CiNN
What about if the <servername> is actually an ip address and not a computer name?
Zerofiz
the ip address will not contain a slash so as long as you are only looking for a slash, no issue.
benPearce
Not sure if it is documented, but PathIsUNCServer() does seem to exist
Anders
A: 

I don't know of a Win32 API for parsing a UNC path; however you should check for:

  • \\computername\share
  • \\?\UNC\computername\share (people use this to access long paths > 260 chars)
  • You can optionally also handle this case: smb://computername/share and this case hostname:/directorypath/resource

Read here for more information

Brian R. Bondy
A: 

This is untested, but maybe a combination of PathIsUNC() and PathFindNextComponent() would do the trick.

Michael Dunn
A: 

If you'll be receiving the data as plain text you should be able to parse it with a simple regex, not sure what language you use but I tend to use perk for quick searches like this. Supposing you have a large document containing multiple lines containing one path per line you can search on \\'s I.e m/\\\\([0-9][0-9][0-9]\.(repeat 3 times, of course not recalling ip address requirements you might need to modify the first one for sure) then\\)? To make it optional and include the trailing slash, and finally (.*)\\/ig it's rough but should do the trick, and the path name should be in $2 for use!

I hope that was clear enough!

onaclov2000