Results 1 to 6 of 6

Thread: UNC to regular path (not the other way!)

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    UNC to regular path (not the other way!)

    Umm i had another post like this, seems like people still didnt understand what I want
    I want to convert a UNC path back to a windows path with drive letters in it. How would i do it?
    ie, i want to convert \\server\share to "d:" if that share is mapped to drive D on the local computer
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: UNC to regular path (not the other way!)

    MrPolite, that was exactly what the example I posted for you did

    what about it didn't do what you were saying? you type in a UNC path in the textbox, and the code will look at all your drive letters to see if one matches that UNC, and gives you the drive letter of the match, if present...

  3. #3
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: UNC to regular path (not the other way!)

    Have you tried FileSystemObject.

    Probabaly, this function is what you are looking for.
    VB Code:
    1. Private Function convertUNCToDrive(ByVal pathName As String) As String
    2.         Dim fileSystem As New FileSystemObjectClass
    3.         Dim pathToReturn As String
    4.         'loop through all drives
    5.         For Each drv As Drive In fileSystem.Drives
    6.             'check if the drive is mapped
    7.             If drv.DriveType = DriveTypeConst.Remote Then
    8.                 'check if the share is same as the path mentioned
    9.                 If pathName.Substring(0, drv.ShareName.Length) = drv.ShareName.ToString Then
    10.                     'replace it with drive letter
    11.                     pathToReturn = pathName.Replace(drv.ShareName, drv.Path)
    12.                     Exit For
    13.                 End If
    14.             End If
    15.         Next
    16.         Return pathToReturn
    17.     End Function
    Add a reference to Microsoft Scripting Runtime. And put Imports Scripting at the top.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: UNC to regular path (not the other way!)

    The wmi sample I had mentioned would do it as well, you would loop all instances of the Win32_LogicalDisk WMI class, see if the "DriveType" property is "4" (meaning Network Drive), then see if the "ProviderName" property (which is the property that lists the network drive UNC path) equals the UNC path you have, then the drive letter is the "name" property of the same object...

    I could do a sample that does this if you really need it, but it seems that you have several examples that might work as well...
    Last edited by gigemboy; Mar 10th, 2006 at 12:56 PM.

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: UNC to regular path (not the other way!)

    Quote Originally Posted by kleinma
    MrPolite, that was exactly what the example I posted for you did

    what about it didn't do what you were saying? you type in a UNC path in the textbox, and the code will look at all your drive letters to see if one matches that UNC, and gives you the drive letter of the match, if present...
    oooooooh sorry
    i dont have visual studio.net.... i was just looking at the API call and judging by what that API call does i thought it's doign the opposite of what i wanted

    okay it's a start... now i guess i should ask the rest in a different forum. Thanks for the solutions guys. I;m doing this in C++ so i should use APIs only not .NET....
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: UNC to regular path (not the other way!)

    you may struggle the api way, you can sometimes get the GetLongPathName api to work, but it can raise issues over server privilages.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width