### Get Name, Path, Ext from Full File Path

The Java File IO class offers many functions.
This is an example to extract file name and file path from a full path (requires the JavaObject library).
'Returns the filename from a fullpath
`Sub GetFileName(path As String) As String
' Define the JavaObject
Dim fileO As JavaObject
' Get the fileio class
fileO.InitializeNewInstance("java.io.File", Array As Object(path))
' Getthe filename
Return fileO.RunMethod("getName", Null)
End Sub`
'Returns the filepath from a fullpath
`Sub GetFilePath(path As String) As String
' Define the JavaObject
Dim fileO As JavaObject
' Get the fileio class
fileO.InitializeNewInstance("java.io.File", Array As Object(path))
' Getthe filename and path
Dim n As String = fileO.RunMethod("getName", Null)
Dim p As String = fileO.RunMethod("getPath", Null)
p = p.Replace(n, "")
Return p
End Sub`
`Private Sub GetFileExtension(path As String) As String 'ignore
Dim pos As Int = path.lastIndexOf(".")
Return path.substring(pos + 1)
End Sub`
`Private Sub HasFileExtension(path As String) As Boolean 'ignore
Dim pos As Int = path.lastIndexOf(".")
Return (pos > 0)
End Sub`
GetFileName without JavaObject
`Sub GetFileName(fullpath As String) As String
Dim i As Int = fullpath.LastIndexOf("\")
If i = -1 Then i = fullpath.LastIndexOf("/")
If i = -1 Then Return fullpath
If i = fullpath.Length - 1 Then Return ""
Return fullpath.SubString(i + 1)
End Sub`

Changed: 2018-05-06 19:32, Category: Files, File: T6C193M1380.htm, ID: 1380