Click here to Skip to main content
15,180,027 members
Articles / Programming Languages / Visual Basic
Tip/Trick
Posted 2 Jul 2010

Tagged as

Stats

26.4K views
4 bookmarked

How to get File Name from Full file Path

Rate me:
Please Sign up or sign in to vote.
3.44/5 (15 votes)
14 Jul 2010CPOL
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)

Share

About the Author

Koshy Panicker John
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 I must admit that i didn't knew it..... Pin
GPUToaster™18-Jul-10 7:56
MemberGPUToaster™18-Jul-10 7:56 
GeneralReason for my vote of 5 Path is one of the great overlooked ... Pin
Martin Jarvis16-Jul-10 9:00
MemberMartin Jarvis16-Jul-10 9:00 
GeneralReason for my vote of 5 Something so simple that has killed ... Pin
Akash Badrinath15-Jul-10 23:46
MemberAkash Badrinath15-Jul-10 23:46 
GeneralReason for my vote of 5 Why the low vote? It taught me somet... Pin
Anthony Daly14-Jul-10 7:37
MemberAnthony Daly14-Jul-10 7:37 
GeneralReason for my vote of 1 how come its a tip/tricks? Pin
Shahriar Iqbal Chowdhury/Galib3-Jul-10 6:24
professionalShahriar Iqbal Chowdhury/Galib3-Jul-10 6:24 
GeneralReason for my vote of 1 default functions Pin
BugByter3-Jul-10 5:25
MemberBugByter3-Jul-10 5:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.