How to VB.Net Path Class

VB.NET provides effective ways of dealing with filenames and paths by using System.IO namespace . The Path Class performs operations on String instances that contain file or directory path information. Path Class returns a string that can contain absolute or relative location information.

The following are the some important operations in VB.Net Path Class:

GetDirectoryName - Returns the directory information for the specified path string.

GetExtension - Returns the extension of the specified path string.

GetFileName - Returns the file name and extension of the specified path string.

GetFileNameWithoutExtension - Returns the file name of the specified path string without the extension.

GetFullPath - Returns the absolute path for the specified path string.

Get Current Application Path

VB.Net Class application in System.Windows.Forms namespace has static property called ExecutablePath . Inorder to get only the folder part of the path, use static method GetDirectoryName of Path class.

It will return the current path of the .exe file .

Imports System.IO

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim tmpPath As String
		Dim rootPath As String
		Dim filename As String
		Dim extension As String
		Dim directory As String
		Dim fullPath As String
		Dim filenameWithoutExtension As String

		tmpPath = "c:\\windows\\inf\\wvmic.inf"

		rootPath = Path.GetPathRoot(tmpPath)
		filename = Path.GetFileName(tmpPath)
		extension = Path.GetExtension(tmpPath)
		directory = Path.GetDirectoryName(tmpPath)
		filenameWithoutExtension = Path.GetFileNameWithoutExtension(tmpPath)
		fullPath = Path.GetFullPath(tmpPath)
	End Sub
End Class (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About