Reputation: 33
How do I find the current name of my launched vb.net project without listing the directory or extension?
I've searched for other solutions, but all of them either has the extension at the end, and/or the directory location at the start, I just want the plain file name, no extension, no directory.
Example:
Dim Filename as string = (code that finds the file name)
MsgBox(Filename)
Which would output Test
as for this example the program was named Test.exe
Upvotes: 0
Views: 1533
Reputation: 1
I tried this:
Public Class FOL
Dim MyFileName = IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath)
Private Sub FOL_Load(sender As Object, e As EventArgs) Handles Me.Load
If MyFileName.Equals("fol") Then
Updater.Show()
End If
End Sub
End Class
This example opens defined form "Updater" before loads main form.
Upvotes: -1
Reputation: 351
Have you tried to look at this one?
Dim PathofYourFile As String = "c:\MyDirectory\MYFile.txt"
Dim FileName As String = IO.Path.GetExtension(PathofYourFile)
MsgBox(FileName)
Upvotes: 0
Reputation: 54417
If this is a WinForms app:
Dim fileName = IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath)
Upvotes: 3