65.9K
CodeProject is changing. Read more.
Home

How to get File Name from Full file Path

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

Jul 14, 2010

CPOL
viewsIcon

81417

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.