[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

VB.Net simple function - output filename of text file

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
doctech
Asked:
doctech
1 Solution
 
sirbountyCommented:
Well, you can use
file.substring(file.lastIndexOf("\")+1)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now