Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

How to get File Name from Full file Path

3.44/5 (15 votes)
14 Jul 2010CPOL 30.2K  
File Name from Path
The following tip will help you to dig out the following details from Full File Path:

1) FileName

2) Extension

3) FileNameWithoutExtension

4) DirectoryName

5) PathRoot

VB
Imports System.IO

Dim _FullPath As String = "C:\Users\Sony\Desktop\Readme.txt"<br>
        MsgBox(Path.GetFileName(_FullPath)) 'Returns >> Readme.txt
        MsgBox(Path.GetExtension(_FullPath)) 'Returns >> .txt
        MsgBox(Path.GetFileNameWithoutExtension(_FullPath)) 'Returns >> Readme
        MsgBox(Path.GetDirectoryName(_FullPath)) 'Returns >> C:\Users\Sony\Desktop
        MsgBox(Path.GetPathRoot(_FullPath)) 'Returns >> C:\</br>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)