Solved

VB.Net simple function - output filename of text file

Posted on 2007-04-02
2
254 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

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

Suggested Solutions

Title # Comments Views Activity
Finding Events logs for IIS website that restarts 2 21
Dinamic report to Crosstab query 9 53
Convert Ctime to date time in textfile? 7 63
VS 2017 18 108
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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