how to remove the filename in the path location

search filename and display the filename and the path location in the

Page 1 of 1

2 Replies - 6355 Views - Last Post: 04 June 2007 - 06:08 AM Rate Topic: ****- 1 Votes

#1 matrik02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-June 07

how to remove the filename in the path location

Post icon  Posted 02 June 2007 - 05:27 AM

I have listview, search button,textbox1,2,3 . I try to find the filename in my directory. I got it and display the filename and the path location in the listview and also in the text2 and text 3 textbox.

The problem is it show the full path location in the text3 like c:\project\data\block\lot.shp. How to remove the filename so that it look like c:\project\data\block\ in the textbox?

Private Sub Insertsub(tempstr As String)
Dim i As Long
Dim sName() As String
Dim sPath As String
sName = Split(tempstr, "\") 'contains File name'

	Dim lvItem As ListItem

	Set lvItem = ListView1.ListItems.Add(, , sName(UBound(sName)))
		lvItem.ListSubItems.Add , , "" & Left$(tempstr, InStr(1, tempstr, Chr$(0)) - 1)
		Text2.Text = sName(UBound(sName)) ' show the data filename
		Text3.Text = tempstr ' show the path location

End Sub









Private Sub Command1_Click() ' search button. When the file name found.It and display it in the listview
	Dim tempstr As String, Ret As Long
  
	tempstr = String(MAX_PATH, 0)
	'returns 1 when successfull, 0 when failed
Ret = SearchTreeForFile("C:\Project\Data\", Text1.Text + ".shp", tempstr)
If Ret <> 0 Then Call Insertsub(tempstr)
ret2 = SearchTreeForFile("C:\Project\Data\", Text1.Text + ".img", tempstr)
If ret2 <> 0 Then Call Insertsub(tempstr)
If Ret = 0 And ret2 = 0 Then MsgBox "File not found"
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: how to remove the filename in the path location

#2 fahimbhamla  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 03-June 07

Re: how to remove the filename in the path location

Posted 03 June 2007 - 02:08 PM

Considering that Text1.Text contains C:\Folder\SubFolder\File.ext
This code would Display C:\Folder\SubFolder\ in Text2
	Dim nPos As Integer
	For nPos = Len(Text1.Text) To 1 Step -1
		If Mid(Text1.Text, nPos, 1) = "\" Then Exit For
	Next
	Text2.Text = Left(Text1.Text, nPos)


Hope that helps you.

This post has been edited by fahimbhamla: 03 June 2007 - 02:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 2much2young  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 16-November 06

Re: how to remove the filename in the path location

Posted 04 June 2007 - 06:08 AM

Left(Text1.Text, InStrRev(Text1.Text, "\") )

or

VB.Left(Text1.Text, InStrRev(Text1.Text, "\") )

This post has been edited by 2much2young: 04 June 2007 - 06:17 AM

Was This Post Helpful? 1

Page 1 of 1