How to convert FILE:///<PATH> to just <PATH>, using built-in classes.

  • Thread starter Thread starter Andrew Backer
  • Start date Start date
A

Andrew Backer

I have a few file:///c:/windows/somewhere style uris that I need to convert
to the actual physical path. I am hoping there is a built in way to handle
this.

I know I can do some text replacing and get the path, at least in this case,
but I'd rather not do that if there is something that already does it more
robustly.

// Andre
 
Andrew Backer said:
I have a few file:///c:/windows/somewhere style uris that I need to
convert to the actual physical path. I am hoping there is a built in way
to handle this.

Take a look at the 'Uri' and 'Path' classes.
 
I have a few file:///c:/windows/somewhere style uris that I need to convert
to the actual physical path.  I am hoping there is a built in way to handle
this.

I know I can do some text replacing and get the path, at least in this case,
but I'd rather not do that if there is something that already does it more
robustly.

// Andrew

Look at System.IO.Path classes.
 
Andrew,

You can hava a look at the uri, however I would just do
\\\
mystring = mystring.tolower.replace(file:///,"")
///

Cor
 
Cor Ligthert said:
You can hava a look at the uri, however I would just do \\\
mystring = mystring.tolower.replace(file:///,"")
///

Hm, this won't change the path separator from "/" to "\". In addition, it
won't decode URL-encoded characters such as spaces ('%20').
 
I have a few file:///c:/windows/somewhere style uris that I need to convert
to the actual physical path. I am hoping there is a built in way to handle
this.

I know I can do some text replacing and get the path, at least in this case,
but I'd rather not do that if there is something that already does it more
robustly.

// Andrew

If you want to get file path without "file:///" you can use substring
function as follows:
Dim a As String = "file:///c:/windows/somewhere/"
MsgBox(a.Substring(8).ToString)

which returns only "c:/windows/somewhere/"

Hope this helps.
 
Herfried?
">
Hm, this won't change the path separator from "/" to "\". In addition, it
won't decode URL-encoded characters such as spaces ('%20').

--
Was that the question?

Cor
 
Herfried K. Wagner said:
Yes:

| I need to convert to the actual physical path.
I thought it was

I have a few file:///c:/windows/somewhere style uris that I need to convert
to the actual physical path

We have probably another OS

Cor
 
Cor Ligthert said:
I thought it was

I have a few file:///c:/windows/somewhere style uris that I need to
convert
to the actual physical path


Yes, but 'c:/windows/some%20directory' is not the local path described by
the URI 'file:///c:/windows/some%20directory'. Instead, it's
'c:\windows\some directory'.
 
Herfried K. Wagner said:
Yes, but 'c:/windows/some%20directory' is not the local path described by
the URI 'file:///c:/windows/some%20directory'. Instead, it's
'c:\windows\some directory'.
Why do you think that I wrote:
"You can always have a look at the Uri"
Do you think that I did not know what you wrote?
(Sounds agresive but is not meant as that, just smiling).

Cor
 
You can create a System.Uri object from your your string. Uri object
has a LocalPath property that returns a system specific path. It
appears to do the trick.
 
Back
Top