|
-
Jun 3rd, 2003, 10:33 AM
#1
Thread Starter
Hyperactive Member
cutting a path
i have a path
f:\Data Team\Bureau\A G Barr Soft Drinks\ILabelClient\db.mdb
i would like to cut it to
f:\Data Team\Bureau\A G Barr Soft Drinks\ILabelClient\
the database filename will be of varying lengths so i assume that i need to say "cut everything after the first '\' from the right" unfortunately i have very little idea about hwo to do that.
any help would be most appreciated
-
Jun 3rd, 2003, 10:41 AM
#2
Frenzied Member
Check this CodeBank thread http://www.vbforums.com/showthread.p...hreadid=244248
You will find a large number of useful file and folder functions here and instructions on how to use it.
In your case, you would need the GetFilePath function
VB Code:
'****************************************************
'* Function: GetFilePath
'* Parameters:
'* FilePath (String) - the full file path of the file
'* Returns: The path of the file in the given file path
'****************************************************
Public Function GetFilePath(FilePath As String) As String
On Error GoTo GetFilePathError
Dim slashLocation As Integer
If Len(FilePath) = 0 Then
GetFilePath = ""
Exit Function
End If
'Find the last \ in the path
slashLocation = InStrRev(FilePath, "\")
If slashLocation = 0 Then
GetFilePath = ""
Else
GetFilePath = Mid$(FilePath, 1, slashLocation)
End If
Exit Function
GetFilePathError:
MsgBox "Error #" & Err.Number & vbCrLf & Err.Description, vbExclamation, "Error"
End Function
-
Jun 3rd, 2003, 10:46 AM
#3
Let me in ..
Re: cutting a path
Originally posted by sagey
i have a path
f:\Data Team\Bureau\A G Barr Soft Drinks\ILabelClient\db.mdb
i would like to cut it to
f:\Data Team\Bureau\A G Barr Soft Drinks\ILabelClient\
the database filename will be of varying lengths so i assume that i need to say "cut everything after the first '\' from the right" unfortunately i have very little idea about hwo to do that.
any help would be most appreciated
VB Code:
Option Explicit
Private Sub Form_Load()
Dim l_strPath As String
Dim l_strArray() As String
Let l_strPath = "f:\Data Team\Bureau\A G Barr Soft Drinks\ILabelClient\db.mdb"
Let l_strArray = Split(l_strPath, "\")
Dim i As Integer
Dim l_strFinalString
For i = LBound(l_strArray) To UBound(l_strArray) - 1
Let l_strFinalString = l_strFinalString & l_strArray(i) & "\"
Next
MsgBox l_strFinalString
End Sub
-
Jun 3rd, 2003, 11:01 AM
#4
Thread Starter
Hyperactive Member
cheers ae_jester
how would i get the filename(and extension) in a string as well as the string holding the path
(i need to use the file name as well in a different part of the app)
thanks for the help so far
-
Jun 3rd, 2003, 11:02 AM
#5
Let me in ..
Originally posted by sagey
cheers ae_jester
how would i get the filename(and extension) in a string as well as the string holding the path
(i need to use the file name as well in a different part of the app)
thanks for the help so far
Use the code i wrote here .... in array you will have everything ...
-
Jun 3rd, 2003, 11:08 AM
#6
Frenzied Member
If you would check that link I gave you, you could have found what you were looking for.
Here it is anyway.
VB Code:
'*******************************************************************************
'** Function: GetFileName
'** Parameters:
'** FilePath (String) - the full file path of the file
'** Returns: The file name of for the given file path
'*******************************************************************************
Public Function GetFileName(FilePath As String) As String
On Error GoTo GetFileNameError
Dim slashLocation As Integer
If Len(FilePath) = 0 Then
GetFileName = ""
Exit Function
End If
'Find the last \ in the path
slashLocation = InStrRev(FilePath, "\")
GetFileName = Mid$(FilePath, slashLocation + 1, Len(FilePath) + 1 - slashLocation)
Exit Function
GetFileNameError:
GetFileName = ""
MsgBox "Error #" & Err.Number & vbCrLf & Err.Description, vbExclamation, "Error"
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|