Results 1 to 5 of 5

Thread: [RESOLVED] Dot in path name

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,333

    Resolved [RESOLVED] Dot in path name

    So I have come up to a opportunity where I am getting a users profile that has a dot in the name, like C:\users\user.ad\appdata. When I send that path to

    Path.GetFileName("C:\users\user.ad\appdata\roaming\apps")

    It errors out as it states the path is invalid. How do I get .Net to treat it as a path instead of a filename.extension?

    I'm am getting the users path by this:

    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

    Any ideas what I can add to tell .Net to treat is as a path?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,809

    Re: Dot in path name

    Escaping it with double backslashes works:
    Code:
    C:\\users\\user.ad\\appdata\\roaming\\apps
    So does using IO.Path.Combine:
    Code:
    IO.Path.Combine("C:\users", "user.ad", "appdata", "roaming", "apps")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,776

    Re: Dot in path name

    What version of .Net are you using? I was using 4.8.

    This worked for me, though GetFileName is returning a directory...

    Code:
            'path = C:\Users\michael.basnett\AppData\Roaming 
            Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
            Dim file As String = IO.Path.GetFileName(path) 'Roaming
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,333

    Re: Dot in path name

    I'm using 4.8, I did get it to work, I just added it like this

    var= Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Apps"

    And sent it along, apparently I thought I had it like that but actually didn't. I was still uing the string as above.

    Thanks guys, seems I just need to post to figure out my own problem.

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,776

    Re: Dot in path name

    Quote Originally Posted by phpman View Post
    I'm using 4.8, I did get it to work, I just added it like this

    var= Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Apps"

    And sent it along, apparently I thought I had it like that but actually didn't. I was still uing the string as above.

    Thanks guys, seems I just need to post to figure out my own problem.
    I would advise against using concatenation. Use IO.Path.Combine

    Code:
            var = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "\Apps")
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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