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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cutting down file name & path using a CHAINSAW????

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I have a string with a path and a file name in:

c:\anicepath\agreatfile.exe

How would I remove the filename from it so that just the path remains. I guess I would use some of these but cant quite figure it out.

object.SelLength [= number]
object.SelStart [= index]
object.SelText [= value]

Am I on the right 'path'?

Thanks

elziko

 
Enable the reference to the Microsoft scripting library and you can use all the normal file commands and separate the path from the application. Its in the help
 
Feed a FileName into the following function and in return you get the pathname:


Private Function ExtractPathName(strFileName As String) As String

Select Case Len(strFileName)
Case Is = 0
ExtractPathName = vbNullString
Case Is > 0
Dim astrFileName() As String
astrFileName = Split(strFileName, "\")
ReDim Preserve astrFileName(LBound(astrFileName) _
To UBound(astrFileName) - 1)
ExtractPathName = Join(astrFileName, "\")
End Select

End Function

Use this as follows:

Dim strFileName As String
Dim strPathName As String
strPathName = ExtractPathName(strFileName)

PS: You need VB6 (Split and Join functions were introduced in that release)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top