How to tell if a file path is local or on a server?
At the moment I do not have access to a multidomain environment.
Nonetheless my application has functions and features which need to run differently if a file is stored locally or on a network.
This means that I have to determine if the files my application is working on are stored locally or on a network, so how can I do this?
A local file's path is typically something like:
C:\Folder\File.txt
A Unc path should look something like this:
\\ComputerName\Folder\File.txt
So far it seems easy, all I need to do is look for "\\" at the start of the path to identify a Unc path, and then I can extract the server name from the path if an api function needs the server name.
Although what about mapped drives? For example if E:\folder\file where E is a drive that is mapped to a server.
As some windows api calls optionally accept the server name do I need to extract it, or can I treat mapped files like local files?
+ do I need to consider other file paths formats?
Re: How to tell if a file path is local or on a server?
Check this page. See also the related topics at the top of the page.
http://vbnet.mvps.org/index.html?cod...slocalpath.htm
Re: How to tell if a file path is local or on a server?
Thanks for the link VBClassicRocks :),
This is the api which is used in the examples:
Code:
Private Declare Function PathIsNetworkPath Lib "shlwapi" _
Alias "PathIsNetworkPathA" _
(ByVal pszPath As String) As Long
and it seems to work for:
1. local paths (including relative paths)
2. mapped drives
3. UNC
4. IP address,
which is good.
I should be able to get to the server name from UNC and IP address paths, which means my only concern is how to extract the server name from a mapped drive path?
Re: How to tell if a file path is local or on a server?
Quote:
Originally Posted by
Witis
... my only concern is how to extract the server name from a mapped drive path?
Try this http://support.microsoft.com/kb/192689
Re: How to tell if a file path is local or on a server?
thanks again LaVolpe, that code looks good so I'll write it in and test it later. rgds