Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net getpath

Status
Not open for further replies.

angela4eva

Programmer
Apr 29, 2005
46
US
how can i get the path from a string
c="c:\prodcuts\newone\bestones\values.zip"
i need to get hut the path from this
"c:\prodcuts\newone\bestones\"
is there a way to do this?
 
This seems to work well:

Private Sub cmdParsePath_Click()
Dim strPath As String
Dim strFileName As String

strPath = txtPath.Text

SeparatePathAndFile strPath, strFileName

lblPath.Caption = strPath
lblFile.Caption = strFileName
End Sub


Private Sub SeparatePathAndFile(ByRef io_strPath As String, ByRef o_strFileName As String)
'io_strPath - Input/output parameter containing the entire path with file name
' - Will Return the path only
'o_strFileName - Output parameter that will contain the name of the File

Dim strPath() As String
Dim lngIndex As Long

strPath() = Split(io_strPath, "\") 'Put the Parts of our path into an array
lngIndex = UBound(strPath)
o_strFileName = strPath(lngIndex) 'Get the File Name from our array
strPath(lngIndex) = "" 'Remove the File Name from our array
io_strPath = Join(strPath, "\") 'Rebuild our path from our array

End Sub
 
Look at system.io.path it has everything you need like getpaht.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
its saying
Dim strPath() As string
Number of indices is less than the number of dimensions of the indexed array.
 
i am using
Console.WriteLine(Path.GetDirectoryName("C:\temp\myfile.txt")
and thsi works liek a charm
thanks
Ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top