[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.Net simple function - output filename of text file

Posted on 2007-04-02
2
Medium Priority
?
258 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 200 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

873 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