Solved

VB.Net simple function - output filename of text file

Posted on 2007-04-02
2
255 Views
Last Modified: 2010-04-14
Hi,
forgive my ignorance but i am only a novice at VB.Net
I am trying to get the string of a file in folder location
At the moment i am using
For Each CurrentFile In Directory.GetFiles(SourceFolder) - this outputs for me the whole string: eg.
c:\source\text.txt
what i want to achieve is the output: text.txt
How do you think i can achieve this
0
Comment
Question by:doctech
[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 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 50 total points
ID: 18837444
Well, you can use
file.substring(file.lastIndexOf("\")+1)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18837719
There are several ways to do it...

You can use System.IO.Path.GetFileName():

        Dim CurrentFile As String
        Dim SourceFolder As String = "C:\"
        For Each CurrentFile In Directory.GetFiles(SourceFolder)
            Debug.Print(Path.GetFileName(CurrentFile))
        Next
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

719 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