-
Apr 12th, 2024, 01:22 PM
#1
Thread Starter
Frenzied Member
[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?
-
Apr 12th, 2024, 01:51 PM
#2
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")
-
Apr 12th, 2024, 02:00 PM
#3
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
-
Apr 12th, 2024, 02:16 PM
#4
Thread Starter
Frenzied Member
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.
-
Apr 12th, 2024, 03:07 PM
#5
Re: Dot in path name
 Originally Posted by phpman
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")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|