I am opening a file, but I would only like to see the filename itself, not the whole path to the image. I've been trying to figure this out for some time, but I finally decided to give up and come to you guys.
Thanks in advance,
MidgetsBro :D
Printable View
I am opening a file, but I would only like to see the filename itself, not the whole path to the image. I've been trying to figure this out for some time, but I finally decided to give up and come to you guys.
Thanks in advance,
MidgetsBro :D
Maybe this helps:
WPCode:Private Sub Form_Load()
Dim FullFile, Filename, Temp As String
Dim I As Integer
FullFile = "c:\MyMap\MySubMap\MyFile.txt"
For I = 0 To Len(FullFile)
Temp = Mid(FullFile, Len(FullFile) - I, 1) 'select 1 character
If Temp = "\" Then 'if the caracter is a slash
Filename = Mid(FullFile, Len(FullFile) - I + 1, I) 'delete the piece of path witch comes before the slash and the slash itself
Exit For
End If
Next I
MsgBox FullFile & " was turned into " & Filename :)
End Sub
Run the code below to see a few of the features of using the FileSystemObject on a file path.
I hope this helps you out.Code:Private Sub Command1_Click()
Dim oFSO As Object
Dim filePath As String
Set oFSO = CreateObject("Scripting.FileSystemObject")
filePath = "c:\folder1\folder2\textfile.txt"
MsgBox "Filename (no extension) = " & oFSO.getbasename(filePath) & vbCrLf & _
"Filename with extension = " & oFSO.getfilename(filePath) & vbCrLf & _
"Extension = " & oFSO.getextensionname(filePath) & vbCrLf & _
"Drive = " & oFSO.getdrivename(filePath)
End Sub