Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB.NET Return short filename

Posted on 2005-02-24
5
Medium Priority
?
390 Views
Last Modified: 2010-04-23
I'm finally converting over to VB.NET and trying to learn all of the new tricks.  I need to return just the file name and extension from a complete file path.  THis was easy using FSO in VB6.  Is there an easy way in .NET?

Example:  

I have C:\WINDOWS\SYSTEM32\SOMEOTHERDIR\FILE1.TXT

I want some easy function where I pass in the above and return just:

FILE1.TXT

Also, does the SYSTEM.IO.FILE.EXIST support UNC file name/paths?
0
Comment
Question by:jimtxas
  • 2
  • 2
5 Comments
 
LVL 12

Assisted Solution

by:S-Twilley
S-Twilley earned 200 total points
ID: 13398116
There may be a better way than this, but you could use the fileinfo object to retrieve information on a file, including its name:

        Dim fiMyFile As IO.FileInfo = New IO.FileInfo("C:\WINDOWS\SYSTEM32\SOMEOTHERDIR\FILE1.TXT")
        MsgBox(fiMyFile.Name)

===================

As for supporting UNC file paths, im not too sure... maybe someone else will answer that in this Q
0
 
LVL 9

Assisted Solution

by:Lacutah
Lacutah earned 200 total points
ID: 13398181
.NET supports UNC file paths just fine.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13398193
Thanks Lacutah... didn't wanna say just incase
0
 
LVL 9

Expert Comment

by:Lacutah
ID: 13398231
I know the feeling - I've stuck my foot in my mouth once or twice before....
0
 
LVL 24

Accepted Solution

by:
Justin_W earned 1600 total points
ID: 13399077
To return just the file name and extension from a complete file path, use:
   System.IO.Path.GetFileName("C:\WINDOWS\SYSTEM32\SOMEOTHERDIR\FILE1.TXT")
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question