Solved

VB.Net simple function - output filename of text file

Posted on 2007-04-02
2
250 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
2 Comments
 
LVL 67

Accepted Solution

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

Expert Comment

by:Mike Tomlinson
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now