Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42732

VS 2010 Removing drive path from full filename

$
0
0
Consider the following examples:
"C:\temp\test.txt"
"C:\temp\test\test1\test.txt"

And other full paths... How can I remove the drive from the start of the string. Following on from the above example, I would like to return:
"temp\test.txt"
"temp\test\test1\test.txt"

I realise that I can just use a string search/replace, but is there some official code to do this via a fileInfo object or other such method? I know that the fileinfo returns the directory name, extension etc. Is there a 'drive' part to a fileInfo object? Or should I use another type of object all together?

Currently I am using this code:

Code:

    Public Function removeDriveFromFilePath(stringFilePath As String) As String
        Dim stringDrivePath As String = Left(stringFilePath, InStr(stringFilePath, "\"))
        Return stringFilePath.Replace(stringDrivePath, "")
    End Function

If however, the drive has a name, that not is in the standard "C:\, D:\, E:\" format, this code will not work.

Viewing all articles
Browse latest Browse all 42732

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>