?
Solved

VB.NET Return short filename

Posted on 2005-02-24
5
Medium Priority
?
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 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