Click here to Skip to main content
11,585,177 members (69,263 online)
Click here to Skip to main content

Tagged as

How to get File Name from Full file Path

, 14 Jul 2010 CPOL 15.2K 1
Rate this:
Please Sign up or sign in to vote.
imports system.iodim Filename as string = "C:\Users\Sony\Desktop\Readme.txt"dim FileInfo as new fileinfo(filename)'this gets the filename and extension e.g. readme.txtmessagebox.show (Fileinfo.name)'this gets the extensionmessagebox.show (Fileinfo.extension)'this gets the...
imports system.io
 
dim Filename as string = "C:\Users\Sony\Desktop\Readme.txt"
dim FileInfo as new fileinfo(filename)
 
'this gets the filename and extension e.g. readme.txt
messagebox.show (Fileinfo.name)
 
'this gets the extension
messagebox.show (Fileinfo.extension)
 
'this gets the directory name
messagebox.show (Fileinfo.Directory)
 
fileinfo = nothing 'i prefer to destory objects rather than waiting for the garbage collector

But you can get more information from the full filename such as:

1. Creation time
2. If the file exists
3. Readonly
4. Last Accesstimes and Writetimes

This is what I would call better file based.

License

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

Share

About the Author

Simon_Whale
Software Developer Oak Underwriting
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
Generalyou comment is taken but I used that method as the rountine ... Pin
Simon_Whale14-Jul-10 3:58
memberSimon_Whale14-Jul-10 3:58 
GeneralReason for my vote of 1 It is better to call a Static method... Pin
KunalChowdhury14-Jul-10 1:32
mvpKunalChowdhury14-Jul-10 1:32 
Reason for my vote of 1
It is better to call a Static method whenever require, instead of creating an instance of FileInfo.

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150707.1 | Last Updated 14 Jul 2010
Article Copyright 2010 by Simon_Whale
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid