### Delete File using FileChooserDialog

An example sub for deleting a file using the FileChooser Dialog.
The filechooser return the full path which is split into folder and filename using JavaObjects.
'Delete a file using filechooser dialog
`Private Sub DeleteFile(folder As String, filename As String)
Dim fc As FileChooser
fc.Initialize
fc.InitialDirectory = folder
fc.InitialFileName = filename
fc.Title = "Delete File"
Dim f As String = fc.ShowSave(MainForm)
If f.Length = 0 Then Return
Try
File.Delete(getFilePath(f), getFileName(f))
Log("File Delete OK: " & LastException.Message)
Catch
Log("File Delete Error: " & LastException.Message)
End Try
End Sub`
'Returns the filename from a fullpath
`Sub getFileName(path As String) As String
'Define the JavaObject
Dim joFile As JavaObject
'Get the fileio class
joFile .InitializeNewInstance("java.io.File", Array As Object(path))
'Get the filename and return
Return joFile .RunMethod("getName", Null)
End Sub`
'Returns the filepath from a fullpath
`Sub getFilePath(path As String) As String
'Define the JavaObject
Dim joFile As JavaObject
'Get the fileio class
joFile.InitializeNewInstance("java.io.File", Array As Object(path))
'Get the filename and path
Dim n As String = joFile.RunMethod("getName", Null)
Dim p As String = joFile.RunMethod("getPath", Null)
p = p.Replace(n, "")
'Return the path
Return p
End Sub`

Changed: , Category: Files, File: T6C193M1374.htm, ID: 1374