Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: UNC path of local folder


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Apr 16, 2015 4:37 PM Last Post By: Remy Lebeau (Te...
Martin Masci

Posts: 29
Registered: 4/3/04
UNC path of local folder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 16, 2015 1:36 PM
I have a folder on my pc like "c:\myfolder\mysubfolder" I want convert this to UNC path like "\\MYPC\myfolder\mysubfolder".
I have try to use ExpandUNCFilename function but with local path I get always "c:\myfolder\mysubfolder".

Is there a way to get always the UNC path also with local path, share or unshare?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: UNC path of local folder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 16, 2015 4:37 PM   in response to: Martin Masci in response to: Martin Masci
Martin wrote:

I have a folder on my pc like "c:\myfolder\mysubfolder" I want convert
this to UNC path like "\\MYPC\myfolder\mysubfolder".

You would have to enumerate the local PC's currently defined UNC shares to
see if any of them map to c:\myfolder\. A PC can have multiple shares, and
multiple shares with different names could be mapped to the same local folder.
So there is no API to convert a local folder to a UNC, but there are ways
to convert a UNC to a local folder.

I have try to use ExpandUNCFilename function but with local path I get
always "c:\myfolder\mysubfolder".

As you should be. That is documented behavior:

http://docwiki.embarcadero.com/Libraries/XE8/en/System.SysUtils.ExpandUNCFileName

Note: ExpandUNCFileName returns a fully qualified path name using Universal
Naming Convention for network files. For files on local disks, ExpandUNCFileName
is equivalent to ExpandFileName. In a UNC file name, the drive prefix is
replaced with the name of the network resource to which the drive is mapped.
For example, if the working directory is J:\ourdir and drive J is mapped
to \\ourserver\ourshare, ExpandUNCFileName('ourfile') returns "\\ourserver\ourshare\ourdir\ourfile".

Is there a way to get always the UNC path also with local path,
share or unshare?

Not directly, no. You would have to hunt for it.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02